﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using BZ.Module;
using BZ.Module.DAL;
using BZ.Module.Model;
using BZ.Utils;
using System.Threading;
using FingerPrintCollection;
using System.IO;
using System.Xml;
using System.Data.SQLite;
using libzkfpcsharp;
using BZ.Logger;
using BZ.Module.StationLogic;
using BZ.Module.BLL;
using BZ.Motion.BLL;
using HalconDotNet;
using BZ.Motion.Card;
using BZ.Module.BLL.StationLogic;

namespace BZ.Frm
{
    public partial class Frm_Login : Form
    {
        public static int Number = 0;
        public static int Number1 = 0;

        #region 变量定义
        Thread startCompareFP = null;
        TipForm tipForm;

        bool b_Clicked = false;

        //文件夹加密以及解密
        public string status;
        string[] arr;
        private string _pathkey;

        bool FPLoginSuccess = false;

        string RootFilepath = Application.StartupPath + @"\hdevengine";

        string FilePath = "";
        string FilePath2 = "";

        string blockSN = "";
        string RightblockSN = "";

        public delegate void ShowMessageDelegate(TextBox tb, string msg);
        bool bFingerDeviceInitOk = false;

        UserFPInfoServices userFPInfoServices = new UserFPInfoServices();
        #endregion

        #region 窗体对象实例，单例模式,保证整个工程只有一个实例
        /// <summary>
        /// 窗体对象实例，单例模式,保证整个工程只有一个实例
        /// </summary>
        private static Frm_Login _instance;
        private static readonly object singletonLock = new object();
        public static Frm_Login Instance
        {
            get
            {
                if (_instance == null)
                {
                    lock (singletonLock)
                    {
                        if (_instance == null)
                        {
                            _instance = new Frm_Login();
                        }
                    }
                }
                return _instance;
            }
        }
        #endregion

        private Frm_Login()
        {
            Common.username = "superadmin";

            InitializeComponent();
            FilePath = RootFilepath + "\\Procedures.{2559a1f2-21d7-11d4-bdaf-00c04f60b9f0}";

            FilePath2 = RootFilepath + "\\Procedures";
            arr = new string[6];
            status = "";
            arr[0] = ".{2559a1f2-21d7-11d4-bdaf-00c04f60b9f0}";
            arr[1] = ".{21EC2020-3AEA-1069-A2DD-08002B30309D}";
            arr[2] = ".{2559a1f4-21d7-11d4-bdaf-00c04f60b9f0}";
            arr[3] = ".{645FF040-5081-101B-9F08-00AA002F954E}";
            arr[4] = ".{2559a1f1-21d7-11d4-bdaf-00c04f60b9f0}";
            arr[5] = ".{7007ACC7-3202-11D1-AAD2-00805FC1270E}";

            FPFuction.AppendUiLog += uiLog3.AppendLogMsg;

            FPFuction.b_startScanFP = false;
            FPFuction.b_recognitioned = false;
        }

        private void Frm_Login_Load(object sender, EventArgs e)
        {
            #region 页面布局
            int userWidth = Screen.PrimaryScreen.Bounds.Width;
            int userHeight = Screen.PrimaryScreen.Bounds.Height;
            int gap = 15;
            int roundRect_Height = 70;
            Point fr_LoginMode_StartPoint = new Point(gap, gap + roundRect_Height);
            #endregion

            if (Common.isFingerPrintInitialed == false)
            {
                groupPanel4.BackColor = Color.Red;
                buttonX1.Enabled = false;
            }
            else
            {
                groupPanel4.BackColor = Color.White;
                buttonX1.Enabled = true;
            }

            #region 设置登录超时计时器(暂时没用)
#if false       

            //---LogIn Time Out
            //设置时间间隔ms
            int interval = 1000;
            Mytimer = new System.Timers.Timer(interval);
            //设置重复计时
            Mytimer.AutoReset = true;
            //设置执行System.Timers.Timer.Elapsed事件
            Mytimer.Elapsed += new System.Timers.ElapsedEventHandler(Mytimer_tick);
#endif
            #endregion
        }

        private void ShowMessage(TextBox tb, string msg)
        {
            if (tb.InvokeRequired)
            {
                //ShowMessageDelegate myDelegate = ShowMessage; //方法1
                ShowMessageDelegate myDelegate = new ShowMessageDelegate(ShowMessage); //方法2
                tb.Invoke(myDelegate, new object[] { tb, msg });
            }
            else
            {
                tb.Text = msg;// + "\r\n";
            }

        }

        private void buttonX1_Click(object sender, EventArgs e)
        {
            FPFuction.b_startScanFP = false;
            Common.b_FPLoginClick = true;

            b_Clicked = true;
            startCompareFP = new Thread(new ThreadStart(StartCompareFP));
            startCompareFP.IsBackground = true;
            startCompareFP.Start();

            tipForm = new TipForm();
            tipForm.Show(this);
        }

        private void Lable_Login_Click(object sender, EventArgs e)
        {
            string UserName = "";

            if (CB_UserName.Text != "")
            {
                switch (CB_UserName.Text)
                {
                    case "Operator":
                        UserName = "Operator";
                        CB_UserName.Text = "";
                        break;
                    case "BZ":
                        UserName = "EN";
                        CB_UserName.Text = "";
                        break;
                    case "Battery QM":
                        CB_UserName.Text = "";
                        UserName = "Battery QM";
                        //buttonX1_Click(sender, e);
                        break;
                    case "Apple":
                        CB_UserName.Text = "";
                        UserName = "Apple";
                        //buttonX1_Click(sender, e);
                        break;
                    default:
                        break;
                }
            }
            else
            {
                MessageBox.Show(this, "请先选择用户名称!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (UserName == "Operator" || UserName == "EN")
            {
                SysUserServices sysUser = new SysUserServices();
                SysUserModel user = sysUser.GetModel(UserName);
                if (user == null) { MessageBox.Show(this, "登陆失败！"); return; }
                if (user.Password != TextBook_Password.Text)
                {
                    if (user.Username != "Operator")
                    {
                        MessageBox.Show(this, "登陆失败！");
                        TextBook_Password.Text = "";
                        return;
                    }
                }
                else
                {
                    TextBook_Password.Text = "";
                }

                Common.username = UserName;
                if (Common.username == "superadmin")
                {
                    Common.Authority = "admin";
                }
                else if (Common.username == "Operator")
                {
                    Common.Authority = "OP";
                }
                else if (Common.username == "EN")
                {
                    Common.Authority = "EN";
                }

                MessageBox.Show(this, "登陆成功！");
            }
            else
            {
                FPLoginSuccess = true;
                buttonX1_Click(sender, e);
            }

            //else
            //{
            //    Common.Authority = "";
            //}
        }

        private void Label_Quit_Click(object sender, EventArgs e)
        {
            //文件夹加密
            if ((Common.Authority == "Apple" || Common.Authority == "CMT") && Common.isFileSetPassCode == false)
            {
                SetPassCode();
                Common.isFileSetPassCode = true;
                //VisionPro.VisionModule.bSetPassCode = true;

                string halconExamples = FileUtils.GetAppDirectory();
                Common.ProcedurePath = halconExamples + @"\hdevengine\procedures.{2559a1f2-21d7-11d4-bdaf-00c04f60b9f0}";

                HalconEngine HalconVisionOperate = new HalconEngine();
                Common.HalconvisionInitil = HalconVisionOperate.IntilCamerafile();

                //记录退出时间
                string endTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                userFPInfoServices.UpdataFPRecordQuit2Table("FPLoginRecord", Common.Id.ToString(), endTime);

            }

            Common.username = "";
            Common.Authority = "OP";

            MessageBox.Show(this, "已退出登陆！");
        }

        private void CB_UserName_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch (CB_UserName.SelectedIndex)
            {
                case 0:
                    TextBook_Password.Enabled = false;
                    break;
                case 1:
                    TextBook_Password.Enabled = true;
                    break;
                case 2:
                    TextBook_Password.Enabled = false;
                    MessageBox.Show(this, "请直接点击登录按钮，进行指纹验证!", "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    break;
                case 3:
                    TextBook_Password.Enabled = false;
                    MessageBox.Show(this, "请直接点击登录按钮，进行指纹验证!", "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    break;
                default:
                    break;
            }
        }

        private void buttonX5_Click(object sender, EventArgs e)
        {
            Dlg_FPLogInRecord FPRecord = new Dlg_FPLogInRecord();
            FPRecord.Show(this);
        }

        private void pictureBox2_DoubleClick(object sender, EventArgs e)
        {
            Dlg_AdminFPRegiste dlg_AdminFPRegiste = new Dlg_AdminFPRegiste();
            dlg_AdminFPRegiste.Show(this);
        }

        private void ucBtnExt_ProductionMode_BtnClick(object sender, EventArgs e)
        {
            if (Common.username == "superadmin"
                   || Common.Authority == "Admin"
                   || Common.Authority == "Apple"
                   || Common.Authority == "CMT"
                   || Common.Authority == "EN"
               )
            {
                if (CLB_ProductMode.GetItemChecked(0))    //左侧工站
                {
                    if (MachineStatusManager.CurrentMachineStatus != MachineStatus.Running
                        || MachineStatusManager.CurrentMachineStatus != MachineStatus.Homing
                        || MachineStatusManager.CurrentMachineStatus != MachineStatus.Alarm
                        || MachineStatusManager.CurrentMachineStatus != MachineStatus.Pause
                        )
                    {
                        Machine.do_上料右正常跑料.ON();
                        Machine.do_上料右空跑.OFF();
                        Machine.do_上料右GRR模式.OFF();
                        Machine.do_上料左正常跑料.ON();
                        Machine.do_上料左空跑.OFF();
                        Machine.do_上料左GRR模式.OFF();
                        StationManager.MachineProductionMode = RunningMode.ProductionMode;
                        ucBtnExt_ProductionMode.FillColor = Color.FromArgb(174, 218, 151);
                        ucBtnExt_EmptyMode.FillColor = Color.FromArgb(238, 238, 237);
                        ucBtnExt_GRRMode.FillColor = Color.FromArgb(238, 238, 237);
                    }
                }
                if (CLB_ProductMode.GetItemChecked(1))  //右侧工站
                {
                    if (MachineStatusManager.CurrentMachineStatus != MachineStatus.Running
                        || MachineStatusManager.CurrentMachineStatus != MachineStatus.Homing
                        || MachineStatusManager.CurrentMachineStatus != MachineStatus.Alarm
                        || MachineStatusManager.CurrentMachineStatus != MachineStatus.Pause
                        )
                    {
                        Machine.do_上料右正常跑料.ON();
                        Machine.do_上料右空跑.OFF();
                        Machine.do_上料右GRR模式.OFF();
                        Machine.do_上料左正常跑料.ON();
                        Machine.do_上料左空跑.OFF();
                        Machine.do_上料左GRR模式.OFF();
                        StationManager.MachineProductionMode = RunningMode.ProductionMode;
                        ucBtnExt_ProductionMode.FillColor = Color.FromArgb(174, 218, 151);
                        ucBtnExt_EmptyMode.FillColor = Color.FromArgb(238, 238, 237);
                        ucBtnExt_GRRMode.FillColor = Color.FromArgb(238, 238, 237);
                    }
                }
                if (CLB_ProductMode.GetItemChecked(0) == false && CLB_ProductMode.GetItemChecked(1) == false)
                {
                    MessageBox.Show(this, "请先选择启动左侧/右侧工站！", "Tip", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            else
            {
                MessageBox.Show(this, "无权限!", "Tip", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        private void ucBtnExt_EmptyMode_BtnClick(object sender, EventArgs e)
        {
            if ((Common.username == "superadmin"
              || Common.Authority == "Admin"
              || Common.Authority == "Apple"
              || Common.Authority == "CMT"
              || Common.Authority == "EN"))
            {

                if (CLB_EmptyMode.GetItemChecked(0)) //左侧工站
                {
                    if (MachineStatusManager.CurrentMachineStatus != MachineStatus.Running
                        || MachineStatusManager.CurrentMachineStatus != MachineStatus.Homing
                        || MachineStatusManager.CurrentMachineStatus != MachineStatus.Alarm
                        || MachineStatusManager.CurrentMachineStatus != MachineStatus.Pause
                        )
                    {
                        Machine.do_上料右正常跑料.OFF();
                        Machine.do_上料右空跑.ON();
                        Machine.do_上料左GRR模式.OFF();
                        StationManager.MachineProductionMode = RunningMode.EmptyMode;
                        ucBtnExt_ProductionMode.FillColor = Color.FromArgb(238, 238, 237);
                        ucBtnExt_EmptyMode.FillColor = Color.FromArgb(174, 218, 151);
                        ucBtnExt_GRRMode.FillColor = Color.FromArgb(238, 238, 237);
                        Machine.do_上料左空跑.ON();
                        Machine.do_上料左正常跑料.OFF();
                        Machine.do_上料左GRR模式.OFF();
                    }
                }

                if (CLB_EmptyMode.GetItemChecked(1))    //右侧工站
                {
                    if (MachineStatusManager.CurrentMachineStatus != MachineStatus.Running
                        || MachineStatusManager.CurrentMachineStatus != MachineStatus.Homing
                        || MachineStatusManager.CurrentMachineStatus != MachineStatus.Alarm
                        || MachineStatusManager.CurrentMachineStatus != MachineStatus.Pause
                        )
                    {
                        Machine.do_上料右正常跑料.OFF();
                        Machine.do_上料右空跑.ON();
                        Machine.do_上料左GRR模式.OFF();
                        StationManager.MachineProductionMode = RunningMode.EmptyMode;
                        ucBtnExt_ProductionMode.FillColor = Color.FromArgb(238, 238, 237);
                        ucBtnExt_EmptyMode.FillColor = Color.FromArgb(174, 218, 151);
                        ucBtnExt_GRRMode.FillColor = Color.FromArgb(238, 238, 237);
                        Machine.do_上料右空跑.ON();
                        Machine.do_上料右正常跑料.OFF();
                        Machine.do_上料右GRR模式.OFF();
                    }
                }


                if (CLB_EmptyMode.GetItemChecked(0) == false && CLB_EmptyMode.GetItemChecked(1) == false)
                {
                    MessageBox.Show(this, "请先选择启动左侧/右侧工站！", "Tip", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            else
            {
                MessageBox.Show(this, "无权限!", "Tip", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        private int SNErrCount = 0;
        private int SNErrCount_R = 0;

        private PointPosition pp;
        private PointPosition Rpp;
        int Step1 = 1;
        int Step2 = 1;
        VisionPlatform.VisionManager.Engine Leng = null;
        VisionPlatform.VisionManager.Engine Reng = null;

        VisionPlatform.VisionManager.Engine Leng_Cal_1 = null;
        VisionPlatform.VisionManager.Engine Leng_Cal_2 = null;
        VisionPlatform.VisionManager.Engine Leng_Cal_3 = null;
        VisionPlatform.VisionManager.Engine Leng_Cal_4 = null;

        VisionPlatform.VisionManager.Engine Reng_Cal_1 = null;
        VisionPlatform.VisionManager.Engine Reng_Cal_2 = null;
        VisionPlatform.VisionManager.Engine Reng_Cal_3 = null;
        VisionPlatform.VisionManager.Engine Reng_Cal_4 = null;

        private int LgrrCount = 0;
        private int RgrrCount = 0;

        private bool LMergedDataFininshed = false;
        private bool RMergedDataFininshed = false;

        HObject LLaserImage = new HObject();
        private void ucBtnExt_GRRMode_BtnClick(object sender, EventArgs e)
        {

            if ((Common.username == "superadmin"
                  || Common.Authority == "Admin"
                  || Common.Authority == "Apple"
                  || Common.Authority == "CMT"
                  || Common.Authority == "EN"))
            {
                if (StationManager.MachineProductionMode != RunningMode.NullMode)
                {
                    MessageBox.Show("当前模式为空跑或者正常生产!,不能跑GRR!");
                    return;
                }

                if (CLB_GrrMode.GetItemChecked(0)) //左侧工站
                {
                    if (MachineStatusManager.CurrentMachineStatus != MachineStatus.Running
                        || MachineStatusManager.CurrentMachineStatus != MachineStatus.Homing
                        || MachineStatusManager.CurrentMachineStatus != MachineStatus.Alarm
                        || MachineStatusManager.CurrentMachineStatus != MachineStatus.Pause
                        )
                    {
                        if (LeftGrrIng == true)
                        {
                            MessageBox.Show("左GRR正在运行");
                            return;
                        }

                        Thread thLeftGrr = new Thread(LeftGrr);
                        thLeftGrr.IsBackground = true;
                        thLeftGrr.Start();

                        ucBtnExt_ProductionMode.FillColor = Color.FromArgb(238, 238, 237);
                        ucBtnExt_EmptyMode.FillColor = Color.FromArgb(238, 238, 237);
                        ucBtnExt_GRRMode.FillColor = Color.FromArgb(174, 218, 151);

                    }
                }

                if (CLB_GrrMode.GetItemChecked(1))    //右侧工站
                {
                    if (MachineStatusManager.CurrentMachineStatus != MachineStatus.Running
                        || MachineStatusManager.CurrentMachineStatus != MachineStatus.Homing
                        || MachineStatusManager.CurrentMachineStatus != MachineStatus.Alarm
                        || MachineStatusManager.CurrentMachineStatus != MachineStatus.Pause
                        )
                    {
                        if (RightGrrIng == true)
                        {
                            MessageBox.Show("右GRR正在运行");
                            return;
                        }

                        Thread thRightGrr = new Thread(RightGrr);
                        thRightGrr.IsBackground = true;
                        thRightGrr.Start();

                        ucBtnExt_ProductionMode.FillColor = Color.FromArgb(238, 238, 237);
                        ucBtnExt_EmptyMode.FillColor = Color.FromArgb(238, 238, 237);
                        ucBtnExt_GRRMode.FillColor = Color.FromArgb(174, 218, 151);
                    }
                }


                if (CLB_GrrMode.GetItemChecked(0) == false && CLB_GrrMode.GetItemChecked(1) == false)
                {
                    MessageBox.Show(this, "请先选择启动左侧/右侧工站！", "Tip", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            else
            {
                MessageBox.Show(this, "无权限!", "Tip", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        private bool LeftGrrIng = false;
        private bool RightGrrIng = false;
        private void LeftGrr()
        {
            LeftGrrIng = true;
            while (true)
            {
                Thread.Sleep(10);
                if (MachineStatusManager.CurrentMachineStatus == MachineStatus.Running)
                {
                    switch (Step1)
                    {
                        case 1:
                            //等待人工放料
                            while (Left_MeasurementLocation.GrrPutProduct == false)
                            {
                                Thread.Sleep(5);
                            }
                            Left_MeasurementLocation.GrrPutProduct = false;
                            Step1 = Step1 + 1;
                            break;

                        case 2: //定位工站吸   定位
                            Machine.do_量测左定位机构载盘吸嘴吸.ON();
                            Machine.do_量测左定位机构定位气缸伸出.OFF();
                            Machine.do_量测左定位机构定位气缸缩回.ON();
                            Thread.Sleep(500);
                            Step1 = Step1 + 1;
                            break;

                        case 3: //摆臂到取料位置   打开摆臂吸气     关闭量测真空
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LlaserInitialPos_Lstation7.X2AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X3初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LccdInitialPos_Lstation6.Z5AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ15初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在FU限位安全位置，请检查");
                                break;
                            }

                            pp = Machine.pos_LrockInitialPos_Lstation5.Clone();
                            pp.isShowY2Position = false;
                            pp.isShowZ6Position = true;
                            pp.AxisPriority = "1";
                            if (MotionControl.AxesMove(pp) == true)
                            {
                                //走Y
                                pp = Machine.pos_Lrock2FetchPos_Lstation5.Clone();
                                pp.isShowY2Position = true;
                                pp.isShowZ6Position = false;
                                pp.AxisPriority = "1";
                                if (MotionControl.AxesMove(pp) == true)
                                {
                                    //走Z
                                    pp = Machine.pos_Lrock2FetchPos_Lstation5.Clone();
                                    pp.isShowY2Position = false;
                                    pp.isShowZ6Position = true;
                                    pp.AxisPriority = "1";
                                    if (MotionControl.AxesMove(pp))
                                    {
                                        Machine.do_量测左搬运工位前吸嘴吸.ON();
                                        Thread.Sleep(500);

                                        Machine.do_量测左定位机构定位气缸伸出.ON();
                                        Machine.do_量测左定位机构定位气缸缩回.OFF();

                                        Machine.do_量测左定位机构载盘吸嘴吸.OFF();
                                        Machine.do_量测左上CCD载盘吸嘴吸.OFF();
                                        Machine.do_量测左上激光载盘吸嘴吸.OFF();
                                        Machine.do_量测左CCD旋转工位吸嘴吸.OFF();
                                        Thread.Sleep(200);
                                        Step1 = Step1 + 1;
                                    }
                                }
                            }
                            break;

                        case 4: //摆臂Z轴提升到安全位置
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LlaserInitialPos_Lstation7.X2AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X3初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LccdInitialPos_Lstation6.Z5AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ15初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在FU限位安全位置，请检查");
                                break;
                            }
                            pp = Machine.pos_LrockInitialPos_Lstation5.Clone();
                            pp.isShowY2Position = false;
                            pp.isShowZ6Position = true;
                            pp.AxisPriority = "1";
                            if (MotionControl.AxesMove(pp) == true)
                            {
                                Step1 = Step1 + 1;
                            }
                            break;

                        case 5: //摆臂到放料位置   关闭摆臂真空   打开量测真空吸
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LlaserInitialPos_Lstation7.X2AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X3初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LccdInitialPos_Lstation6.Z5AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ15初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在负限位安全位置，请检查");
                                break;
                            }
                            //TODO X轴移动到放料位
                            pp = Machine.pos_Lrock2PutPos_Lstation5.Clone();
                            pp.isShowY2Position = true;
                            pp.isShowZ6Position = false;
                            pp.AxisPriority = "1";
                            if (MotionControl.AxesMove(pp) == true)
                            {
                                pp = Machine.pos_Lrock2PutPos_Lstation5.Clone();
                                pp.isShowY2Position = false;
                                pp.isShowZ6Position = true;
                                pp.AxisPriority = "1";
                                if (MotionControl.AxesMove(pp) == true)
                                {
                                    Machine.do_量测左上CCD载盘吸嘴吸.ON();
                                    Thread.Sleep(500);
                                    Machine.do_量测左搬运工位前吸嘴吸.OFF();
                                    Machine.do_量测左搬运工位中吸嘴吸.OFF();
                                    Machine.do_量测左搬运工位后吸嘴吸.OFF();
                                    Thread.Sleep(200);

                                    Step1 = Step1 + 1;
                                }
                            }
                            break;

                        case 6: //摆臂到安全位置     
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LlaserInitialPos_Lstation7.X2AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X3初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LccdInitialPos_Lstation6.Z5AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ15初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在负限位安全位置，请检查");
                                break;
                            }
                            pp = Machine.pos_LrockSaftPos_Lstation5.Clone();
                            pp.isShowY2Position = false;
                            pp.isShowZ6Position = true;
                            pp.AxisPriority = "1";
                            if (MotionControl.AxesMove(pp) == true)
                            {
                                if (MotionControl.AxesMove(Machine.pos_LrockSaftPos_Lstation5))
                                {
                                    Step1 = Step1 + 1;
                                }
                            }
                            break;

                        /////////////////////////////////上CCD拍照处理//////////////////////////////////////
                        #region 上CCD拍照处理
                        case 7:
                            if (MotionControl.AxesMove(Machine.pos_LccdMeasureBlockPos_Lstation6))
                            {
                                Step1 = Step1 + 1;
                            }
                            break;

                        case 8:   //拍照视觉处理                  //拍第一次背光，计算FAI1
                                  //判断是否是点检模式
                            if (Common.isPointCheckModel == true)
                            {
                                Common.light1.WriteData(Common.lightList[(int)LIGHT_ENUM.左工位2上环光].Chanel, Common.lightList[(int)LIGHT_ENUM.左工位2上环光].Value);
                                Machine.SecondComputerSocket.SendStr("Station2_block" + Environment.NewLine);

                                while (Common.strStation_Block.Contains("Station_Block") == false)
                                {
                                    Thread.Sleep(10);
                                }
                                Common.light1.WriteData(Common.lightList[(int)LIGHT_ENUM.左工位2上环光].Chanel, 0);
                                string[] str = Common.strStation_Block.Split(',');
                                Common.ProductTypeRight = Convert.ToInt32(str[2].Split(':')[1]);
                                RightblockSN = str[1].Split(':')[1];
                                Common.strStation_Block = "";
                            }

                            MotionControl.AxesMove(Machine.pos_RccdMeasurePos_Rstation6);
                            //拍第一次背光
                            Common.light1.WriteData(Common.lightList[(int)LIGHT_ENUM.左工位2下背光].Chanel, Common.lightList[(int)LIGHT_ENUM.左工位2下背光].Value);
                            Thread.Sleep(50);

                            //给副工控机发拍第一次拍照指令
                            Machine.SecondComputerSocket.SendStr("Station2_1" + Environment.NewLine);
                            while (Common.strStation1_1 != "Station2,1")
                            {
                                Thread.Sleep(10);
                            }
                            Common.strStation1_1 = "";
                            Common.light1.WriteData(Common.lightList[(int)LIGHT_ENUM.左工位2下背光].Chanel, 0);

                            Step1 = Step1 + 1;
                            break;

                        case 9:   //测量完成，Z轴移动到初始位置
                            if (MotionControl.AxesMove(Machine.pos_LccdInitialPos_Lstation6))
                            {
                                Step1 = Step1 + 1;
                            }
                            break;

                        case 10:   //等待视觉处理结果
                            string strLeftStation2 = string.Empty;
                            try
                            {
                                //不同类型产品调用不同的算法
                                if (Common.ProductType == -1)
                                {
                                    Leng = new VisionPlatform.VisionManager.Engine("Station2");
                                }
                                else if (Common.ProductType == 1)
                                {
                                    Leng = new VisionPlatform.VisionManager.Engine("Station2_Min");
                                }
                                else if (Common.ProductType == 2)
                                {
                                    Leng = new VisionPlatform.VisionManager.Engine("Station2_Mid");
                                }
                                else if (Common.ProductType == 3)
                                {
                                    Leng = new VisionPlatform.VisionManager.Engine("Station2_Max");
                                }
                                Leng.ActionFun();
                                strLeftStation2 = Leng.GetOutputString("Station2Result");
                                Common.upCCDImage1 = Leng.GetOutputImage("ImageOrg_Ring");
                                Common.upCCDImage2 = Leng.GetOutputImage("ImageOrg_Back");
                                Leng = null;
                            }
                            catch
                            {
                                strLeftStation2 = "LeftStation2OK" + "," + "FAI1:" + 9999 + "," + "FAI3:" + 9999 + "," + "FAI4:" + 9999;
                            }

                            //数据融合
                            string[] revData1 = strLeftStation2.Split(',');
                            MeasureProduct mp = new MeasureProduct();

                            //图片入队
                            //mp.upCCDImageSN = Common.upCCDImageSN;
                            mp.upCCDImage1 = Common.upCCDImage1;
                            mp.upCCDImage2 = Common.upCCDImage2;

                            for (int i = 0; i < revData1.Length; i++)
                            {
                                if (revData1[i].Contains(":"))
                                {
                                    string FAIName = revData1[i].Split(':')[0];
                                    string FAIValue = revData1[i].Split(':')[1];
                                    DataItem FAI = new DataItem();
                                    FAI.Name = FAIName;
                                    FAI.Value = double.Parse(FAIValue);
                                    FAI.Position = 0;
                                    mp.MeasureData.Add(FAI);
                                }
                            }
                            mp.whichBlock = Common.ProductType;
                            //数据入队
                            Common.Station2Queue_L.Enqueue(mp);
                            Step1 = Step1 + 1;
                            break;
                        #endregion

                        case 11: //摆臂到取料位置
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LlaserInitialPos_Lstation7.X2AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X3初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LccdInitialPos_Lstation6.Z5AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ15初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在负限位安全位置，请检查");
                                break;
                            }

                            pp = Machine.pos_LrockInitialPos_Lstation5.Clone();
                            pp.isShowY2Position = false;
                            pp.isShowZ6Position = true;
                            pp.AxisPriority = "1";
                            if (MotionControl.AxesMove(pp) == true)
                            {
                                //走Y
                                pp = Machine.pos_Lrock2FetchPos_Lstation5.Clone();
                                pp.isShowY2Position = true;
                                pp.isShowZ6Position = false;
                                pp.AxisPriority = "1";
                                if (MotionControl.AxesMove(pp) == true)
                                {
                                    //走Z
                                    pp = Machine.pos_Lrock2FetchPos_Lstation5.Clone();
                                    pp.isShowY2Position = false;
                                    pp.isShowZ6Position = true;
                                    pp.AxisPriority = "1";
                                    if (MotionControl.AxesMove(pp))
                                    {
                                        Machine.do_量测左搬运工位中吸嘴吸.ON();
                                        Thread.Sleep(500);
                                        Machine.do_量测左定位机构载盘吸嘴吸.OFF();
                                        Machine.do_量测左上CCD载盘吸嘴吸.OFF();
                                        Machine.do_量测左上激光载盘吸嘴吸.OFF();
                                        Machine.do_量测左CCD旋转工位吸嘴吸.OFF();
                                        Step1 = Step1 + 1;
                                    }
                                }
                            }
                            break;

                        case 12: //摆臂Z轴提升到安全位置
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LlaserInitialPos_Lstation7.X2AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X3初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LccdInitialPos_Lstation6.Z5AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ15初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在负限位安全位置，请检查");
                                break;
                            }
                            pp = Machine.pos_LrockInitialPos_Lstation5.Clone();
                            pp.isShowY2Position = false;
                            pp.isShowZ6Position = true;
                            pp.AxisPriority = "1";
                            if (MotionControl.AxesMove(pp) == true)
                            {
                                Step1 = Step1 + 1;
                            }
                            break;

                        #region 下CCD拍照处理
                        case 13:  //如果需要下CCD拍照则移动到下CCD 拍照位置  
                            if (MotionControl.AxesMove(Machine.pos_Lrock2BottomCCDPos_Lstation5))
                            {
                                Step1 = Step1 + 1;
                            }
                            break;

                        case 14:
                            Common.light3.WriteData(Common.lightList[(int)LIGHT_ENUM.左工位3下同轴光SN].Chanel, Common.lightList[(int)LIGHT_ENUM.左工位3下同轴光SN].Value);
                            Thread.Sleep(50);
                            //发送第一次拍照
                            Machine.SecondComputerSocket.SendStr("Station3_1" + Environment.NewLine);
                            while (Common.strStation3_1 == string.Empty)
                            {
                                Thread.Sleep(10);
                            }
                            Common.strStation3_1 = string.Empty;
                            Common.light3.WriteData(Common.lightList[(int)LIGHT_ENUM.左工位3下同轴光SN].Chanel,0);

                            //发送第2次拍照
                            Common.light3.WriteData(Common.lightList[(int)LIGHT_ENUM.左工位3下同轴光].Chanel, Common.lightList[(int)LIGHT_ENUM.左工位3下同轴光].Value);
                            Machine.SecondComputerSocket.SendStr("Station3_2" + Environment.NewLine);
                            while (Common.strStation3_2 == string.Empty)
                            {
                                Thread.Sleep(10);
                            }
                            Common.strStation3_2 = string.Empty;
                            Common.light3.WriteData(Common.lightList[(int)LIGHT_ENUM.左工位3下同轴光].Chanel, 0);

                            //发送第3次拍照
                            Common.light3.WriteData(Common.lightList[(int)LIGHT_ENUM.左工位3下同轴光2].Chanel, Common.lightList[(int)LIGHT_ENUM.左工位3下同轴光2].Value);
                            Machine.SecondComputerSocket.SendStr("Station3_3" + Environment.NewLine);
                            while (Common.strStation3_3 == string.Empty)
                            {
                                Thread.Sleep(10);
                            }
                            Common.strStation3_3 = string.Empty;
                            Common.light3.WriteData(Common.lightList[(int)LIGHT_ENUM.左工位3下同轴光2].Chanel, 0);

                            //获取结果
                            Machine.SecondComputerSocket.SendStr("Station3_Calculation" + Environment.NewLine);
                            while (Common.strStation3 == string.Empty)
                            {
                                Thread.Sleep(10);
                            }

                            string strRightStation3 = string.Empty;
                            strRightStation3 = Common.strStation3;
                            Common.strStation3 = string.Empty;

                            Common.AppendUiLog.Log(strRightStation3, LogType.Alert);

                            //数据融合
                            string[] revData13 = strRightStation3.Split(',');
                            MeasureProduct mp3 = new MeasureProduct();
                            Common.Station2Queue_L.TryDequeue(out mp3);
                            for (int i = 0; i < revData13.Length; i++)
                            {
                                if (revData13[i].Contains(":"))
                                {
                                    string FAIName = revData13[i].Split(':')[0];
                                    string FAIValue = revData13[i].Split(':')[1];
                                    DataItem FAI = new DataItem();
                                    FAI.Name = FAIName;
                                    if (FAIName != "SN")
                                    {
                                        FAI.Value = double.Parse(FAIValue);
                                        FAI.Position = 0;
                                        mp3.MeasureData.Add(FAI);
                                    }
                                    else
                                    {
                                        if (Common.isPointCheckModel == false)
                                        {
                                            mp3.SN = FAIValue;
                                        }
                                        else
                                        {
                                            mp3.SN = RightblockSN;
                                        }
                                    }
                                }
                            }
                            //数据入队
                            Common.Station3Queue_L.Enqueue(mp3);
                            Step1 = Step1 + 1;
                            break;
                        #endregion

                        case 15: //摆臂到放料位置   关闭摆臂真空   打开量测真空吸
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LlaserInitialPos_Lstation7.X2AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X3初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LccdInitialPos_Lstation6.Z5AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ15初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在负限位安全位置，请检查");
                                break;
                            }
                            //TODO X轴移动到放料位
                            pp = Machine.pos_Lrock2PutPos_Lstation5.Clone();
                            pp.isShowY2Position = true;
                            pp.isShowZ6Position = false;
                            pp.AxisPriority = "1";
                            if (MotionControl.AxesMove(pp) == true)
                            {
                                pp = Machine.pos_Lrock2PutPos_Lstation5.Clone();
                                pp.isShowY2Position = false;
                                pp.isShowZ6Position = true;
                                pp.AxisPriority = "1";
                                if (MotionControl.AxesMove(pp) == true)
                                {
                                    Machine.do_量测左上激光载盘吸嘴吸.ON();       ////激光
                                    Thread.Sleep(500);

                                    Machine.do_量测左搬运工位前吸嘴吸.OFF();
                                    Machine.do_量测左搬运工位中吸嘴吸.OFF();
                                    Machine.do_量测左搬运工位后吸嘴吸.OFF();
                                    Thread.Sleep(200);


                                    Step1 = Step1 + 1;
                                }
                            }
                            break;

                        case 16: //摆臂到安全位置   
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LlaserInitialPos_Lstation7.X2AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X3初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LccdInitialPos_Lstation6.Z5AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ15初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在负限位安全位置，请检查");
                                break;
                            }
                            pp = Machine.pos_LrockSaftPos_Lstation5.Clone();
                            pp.isShowY2Position = false;
                            pp.isShowZ6Position = true;
                            pp.AxisPriority = "1";
                            if (MotionControl.AxesMove(pp) == true)
                            {
                                if (MotionControl.AxesMove(Machine.pos_LrockSaftPos_Lstation5))
                                {
                                    Step1 = Step1 + 1;
                                }
                            }
                            break;

                        #region 激光处理
                        case 17:  //移动到激光测试的初始位置
                            if (MotionControl.AxesMove(Machine.pos_LlaserStartPos_Lstation7))
                            {
                                Step1 = Step1 + 1;
                            }
                            break;

                        case 18:   //打开激光触发
                            Machine.SecondComputerSocket.SendStr("LaserStart" + Environment.NewLine);
                            while (Common.strStation4LaserStart != "LaserStart")
                            {
                                Thread.Sleep(10);
                            }
                            Machine.do_左工位点激光触发.ON();
                            Step1 = Step1 + 1;
                            break;

                        case 19:   //运动到激光测量终点位置
                            if (MotionControl.AxesMove(Machine.pos_LlaserEndPos_Lstation7))
                            {
                                Machine.do_左工位点激光触发.OFF();
                                Step1 = Step1 + 1;
                            }
                            break;

                        case 20:     //采图并关闭激光触发
                            Machine.SecondComputerSocket.SendStr("LaserStop" + Environment.NewLine);
                            while (Common.strStation4 == string.Empty)
                            {
                                Thread.Sleep(10);
                            }
                            Step1 = Step1 + 1;
                            break;

                        case 21:    //激光处理
                            if (MotionControl.AxesMove(Machine.pos_LlaserInitialPos_Lstation7))//运动到安全位   
                            {
                                string strLeftStation4 = string.Empty;
                                strLeftStation4 = Common.strStation4;
                                Common.strStation4 = string.Empty;

                                //数据拆分
                                Common.AppendUiLog.Log(strLeftStation4, LogType.Alert);
                                string[] revData14 = strLeftStation4.Split(',');
                                //数据融合
                                MeasureProduct mp4 = new MeasureProduct();
                                Common.Station3Queue_L.TryDequeue(out mp4);
                                for (int i = 0; i < revData14.Length; i++)
                                {
                                    if (revData14[i].Contains(":"))
                                    {
                                        string FAIName = revData14[i].Split(':')[0];
                                        string FAIValue = revData14[i].Split(':')[1];
                                        DataItem FAI = new DataItem();
                                        FAI.Name = FAIName;
                                        FAI.Value = double.Parse(FAIValue);
                                        FAI.Position = 0;
                                        mp4.MeasureData.Add(FAI);
                                    }
                                }
                                //数据入队
                                Common.Station4Queue_L.Enqueue(mp4);
                                Step1 = Step1 + 1;
                            }
                            break;

                        case 22: //等待激光处理结果并轴回到初始位
                            if (MotionControl.CheckMoveDone(Machine.pos_LlaserInitialPos_Lstation7))
                            {
                                Step1 = Step1 + 1;
                            }
                            break;
                        #endregion

                        case 23: //摆臂到取料位置
                            Thread.Sleep(500);
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LlaserInitialPos_Lstation7.X2AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X3初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LccdInitialPos_Lstation6.Z5AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ15初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在负限位安全位置，请检查");
                                break;
                            }

                            pp = Machine.pos_LrockInitialPos_Lstation5.Clone();
                            pp.isShowY2Position = false;
                            pp.isShowZ6Position = true;
                            pp.AxisPriority = "1";
                            if (MotionControl.AxesMove(pp) == true)
                            {
                                //走Y
                                pp = Machine.pos_Lrock2FetchPos_Lstation5.Clone();
                                pp.isShowY2Position = true;
                                pp.isShowZ6Position = false;
                                pp.AxisPriority = "1";
                                if (MotionControl.AxesMove(pp) == true)
                                {
                                    //走Z
                                    pp = Machine.pos_Lrock2FetchPos_Lstation5.Clone();
                                    pp.isShowY2Position = false;
                                    pp.isShowZ6Position = true;
                                    pp.AxisPriority = "1";
                                    if (MotionControl.AxesMove(pp))
                                    {
                                        Machine.do_量测左搬运工位后吸嘴吸.ON();
                                        Thread.Sleep(500);
                                        Machine.do_量测左定位机构载盘吸嘴吸.OFF();
                                        Machine.do_量测左上CCD载盘吸嘴吸.OFF();
                                        Machine.do_量测左上激光载盘吸嘴吸.OFF();
                                        Machine.do_量测左CCD旋转工位吸嘴吸.OFF();
                                        Step1 = Step1 + 1;
                                    }
                                }
                            }
                            break;

                        case 24: //摆臂Z轴提升到安全位置
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LlaserInitialPos_Lstation7.X2AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X3初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LccdInitialPos_Lstation6.Z5AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ15初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在负限位安全位置，请检查");
                                break;
                            }
                            pp = Machine.pos_LrockInitialPos_Lstation5.Clone();
                            pp.isShowY2Position = false;
                            pp.isShowZ6Position = true;
                            pp.AxisPriority = "1";
                            if (MotionControl.AxesMove(pp) == true)
                            {
                                Step1 = Step1 + 1;
                            }
                            break;

                        case 25: //摆臂到放料位置   关闭摆臂真空   打开量测真空吸
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LlaserInitialPos_Lstation7.X2AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X3初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LccdInitialPos_Lstation6.Z5AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ15初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在负限位安全位置，请检查");
                                break;
                            }
                            //TODO X轴移动到放料位
                            pp = Machine.pos_Lrock2PutPos_Lstation5.Clone();
                            pp.isShowY2Position = true;
                            pp.isShowZ6Position = false;
                            pp.AxisPriority = "1";
                            if (MotionControl.AxesMove(pp) == true)
                            {
                                pp = Machine.pos_Lrock2PutPos_Lstation5.Clone();
                                pp.isShowY2Position = false;
                                pp.isShowZ6Position = true;
                                pp.AxisPriority = "1";
                                if (MotionControl.AxesMove(pp) == true)
                                {
                                    Machine.do_量测左CCD旋转工位吸嘴吸.ON();  ////激光
                                    Thread.Sleep(500);

                                    Machine.do_量测左搬运工位前吸嘴吸.OFF();
                                    Machine.do_量测左搬运工位中吸嘴吸.OFF();
                                    Machine.do_量测左搬运工位后吸嘴吸.OFF();
                                    Thread.Sleep(200);


                                    Step1 = Step1 + 1;
                                }
                            }
                            break;

                        case 26: //摆臂到安全位置   
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LlaserInitialPos_Lstation7.X2AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X3初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LccdInitialPos_Lstation6.Z5AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ15初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在负限位安全位置，请检查");
                                break;
                            }
                            pp = Machine.pos_LrockSaftPos_Lstation5.Clone();
                            pp.isShowY2Position = false;
                            pp.isShowZ6Position = true;
                            pp.AxisPriority = "1";
                            if (MotionControl.AxesMove(pp) == true)
                            {
                                if (MotionControl.AxesMove(Machine.pos_LrockSaftPos_Lstation5))
                                {
                                    Step1 = Step1 + 1;
                                }
                            }
                            break;

                        #region 旋转工位拍照计算
                        case 27:
                            //TODO 旋转45°
                            if (MotionControl.AxesMove(Machine.pos_Lrotate1Pos_Lstation8) == true)
                            {
                                Step1 = Step1 + 1;
                            }
                            break;

                        case 28:  //第一次拍照
                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.左工位5侧背光].Chanel, Common.lightList[(int)LIGHT_ENUM.左工位5侧背光].Value);
                            Thread.Sleep(100);
                            //第一次拍照指令
                            Machine.SecondComputerSocket.SendStr("Station5,1" + Environment.NewLine);
                            while (Common.strStation5_1 != "Station5,1")
                            {
                                Thread.Sleep(10);
                            }
                            Common.strStation5_1 = "";
                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.左工位5侧背光].Chanel, 0);
                            Step1 = Step1 + 1;
                            break;

                        case 29:  //调用计算的视觉算子
                            Machine.SecondComputerSocket.SendStr("Station5_1_Calculation" + Environment.NewLine);
                            while (Common.strStation5_Cam1OK != "Cam1OK")
                            {
                                Thread.Sleep(10);
                            }
                            Common.strStation5_Cam1OK = "";
                            Step1 = Step1 + 1;
                            break;

                        case 30:
                            //TODO 旋转45°
                            if (MotionControl.AxesMove(Machine.pos_Lrotate2Pos_Lstation8) == true)
                            {
                                Step1 = Step1 + 1;
                            }
                            break;

                        case 31: //第二次拍照
                            Thread.Sleep(100);
                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.左工位5侧背光].Chanel, Common.lightList[(int)LIGHT_ENUM.左工位5侧背光].Value);
                            Thread.Sleep(100);
                            //第二次拍照指令
                            Machine.SecondComputerSocket.SendStr("Station5,2" + Environment.NewLine);
                            while (Common.strStation5_2 != "Station5,2")
                            {
                                Thread.Sleep(10);
                            }
                            Common.strStation5_2 = "";
                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.左工位5侧背光].Chanel, 0);
                            Step1 = Step1 + 1;
                            break;

                        case 32:
                            Machine.SecondComputerSocket.SendStr("Station5_2_Calculation" + Environment.NewLine);
                            while (Common.strStation5_Cam2OK != "Cam2OK")
                            {
                                Thread.Sleep(10);
                            }
                            Common.strStation5_Cam2OK = "";
                            Step1 = Step1 + 1;
                            break;

                        case 33:
                            //TODO 旋转45°
                            if (MotionControl.AxesMove(Machine.pos_Lrotate3Pos_Lstation8) == true)
                            {
                                Step1 = Step1 + 1;
                            }
                            break;

                        case 34:  //第三次拍照
                            Thread.Sleep(100);
                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.左工位5侧背光].Chanel, Common.lightList[(int)LIGHT_ENUM.左工位5侧背光].Value);
                            Thread.Sleep(100);
                            //第三次拍照指令
                            Machine.SecondComputerSocket.SendStr("Station5,3" + Environment.NewLine);
                            while (Common.strStation5_3 != "Station5,3")
                            {
                                Thread.Sleep(10);
                            }
                            Common.strStation5_3 = "";
                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.左工位5侧背光].Chanel, 0);
                            Step1 = Step1 + 1;
                            break;

                        case 35:
                            Machine.SecondComputerSocket.SendStr("Station5_3_Calculation" + Environment.NewLine);
                            while (Common.strStation5_Cam3OK != "Cam3OK")
                            {
                                Thread.Sleep(10);
                            }
                            Common.strStation5_Cam3OK = "";
                            break;

                        case 36:
                            //TODO 旋转45°
                            if (MotionControl.AxesMove(Machine.pos_Lrotate4Pos_Lstation8) == true)
                            {
                                Step1 = Step1 + 1;
                            }
                            break;

                        case 37:// 第4次拍照
                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.左工位5侧背光].Chanel, Common.lightList[(int)LIGHT_ENUM.左工位5侧背光].Value);
                            Thread.Sleep(50);
                            //第四次拍照指令
                            Machine.SecondComputerSocket.SendStr("Station5,4" + Environment.NewLine);
                            while (Common.strStation5_4 != "Station5,4")
                            {
                                Thread.Sleep(10);
                            }
                            Common.strStation5_4 = "";
                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.左工位5侧背光].Chanel, 0);
                            Step1 = Step1 + 1;
                            break;

                        case 38:
                            Machine.SecondComputerSocket.SendStr("Station5_4_Calculation" + Environment.NewLine);
                            while (Common.strStation5_Cam4OK != "Cam4OK")
                            {
                                Thread.Sleep(10);
                            }
                            Common.strStation5_Cam4OK = "";
                            Step1 = Step1 + 1;
                            break;

                        case 39:    //旋转轴转到初始位置
                            MotionControl.AxesMoveNoWait(Machine.pos_LrotateInitialPos_Lstation8);//异步运动到安全位
                            Step1 = Step1 + 1;
                            break;

                        case 40:
                            //发送允许计算指令
                            Machine.SecondComputerSocket.SendStr("Station5_Calculation" + Environment.NewLine);
                            while (Common.strStation5 == string.Empty)
                            {
                                Thread.Sleep(10);
                            }
                            string strLeftStation5 = string.Empty;

                            strLeftStation5 = Common.strStation5;
                            Common.strStation5 = string.Empty;

                            //strLeftStation5 = strLeftStation5 = "RightStation3OK" + "," + "FAI5:" + 9999 + "," + "FAI6:" + 9999 + "," + "FAI7:" + 9999 + "," + "FAI8:" + 9999 + "," + "FAI9:" + 9999;
                            Common.AppendUiLog.Log(strLeftStation5, LogType.Alert);

                            //数据融合
                            string[] revData15 = strLeftStation5.Split(',');
                            MeasureProduct mp5 = new MeasureProduct();
                            Common.Station4Queue_L.TryDequeue(out mp5);
                            mp5.Position = "1";
                            for (int i = 0; i < revData15.Length; i++)
                            {
                                if (revData15[i].Contains(":"))
                                {
                                    string FAIName = revData15[i].Split(':')[0];
                                    string FAIValue = revData15[i].Split(':')[1];
                                    DataItem FAI = new DataItem();
                                    FAI.Name = FAIName;
                                    FAI.Value = double.Parse(FAIValue);
                                    FAI.Position = 0;
                                    mp5.MeasureData.Add(FAI);
                                }
                            }
                            //数据入队
                            Common.Station5Queue_L.Enqueue(mp5);
                            Step1 = Step1 + 1;
                            break;

                        case 41:      //整合产品的数据
                            MeasureProduct mp1 = new MeasureProduct();
                            Common.Station5Queue_L.TryDequeue(out mp1);
                            JUDGEMENT_RESULT ret = ProcessData.PrcessData(mp1);

                            string result = "";
                            if (ret == JUDGEMENT_RESULT.OK)
                            {
                                result = "OK";
                            }
                            else
                            {
                                result = "NG";
                            }

                            //保存图片
                            Task.Run(() =>
                            {
                                //Common.motionControl.SaveProducetImageWithBarCode(mp1.upCCDImageSN, "upCCDImageSN", mp1.SN);
                                Common.motionControl.SaveProducetImageWithBarCode(mp1.upCCDImage1, "upCCDImage1", mp1.SN, result);
                                Common.motionControl.SaveProducetImageWithBarCode(mp1.upCCDImage2, "upCCDImage2", mp1.SN, result);

                                Common.motionControl.SaveProducetImageWithBarCode(mp1.downCCDImage, "downCCDImage", mp1.SN, result);
                                Common.motionControl.SaveProducetImageWithBarCode(mp1.LaserImage, "LaserImage", mp1.SN, result);

                                Common.motionControl.SaveProducetImageWithBarCode(mp1.RoteImage1, "RoteImage1", mp1.SN, result);
                                Common.motionControl.SaveProducetImageWithBarCode(mp1.RoteImage2, "RoteImage2", mp1.SN, result);
                                Common.motionControl.SaveProducetImageWithBarCode(mp1.RoteImage3, "RoteImage3", mp1.SN, result);
                                Common.motionControl.SaveProducetImageWithBarCode(mp1.RoteImage4, "RoteImage4", mp1.SN, result);
                            });

                            LMergedDataFininshed = true;
                            Step1 = Step1 + 1;
                            break;

                        case 42:   //等待旋转轴转到初始位置
                            if (MotionControl.CheckMoveDone(Machine.pos_LrotateInitialPos_Lstation8))
                            {
                                Step1 = Step1 + 1;
                            }

                            break;

                        case 43:    //等待数据整合完成
                            if (LMergedDataFininshed == true)
                            {
                                LMergedDataFininshed = false;
                                Step1 = Step1 + 1;
                            }
                            break;
                        #endregion

                        ///////////////////////////////////////开始返回/////////////////////////////////////////
                        #region 第一次返回
                        case 44: //摆臂到放料位置   关闭摆臂真空   打开量测真空吸
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LlaserInitialPos_Lstation7.X2AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X3初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LccdInitialPos_Lstation6.Z5AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ15初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在负限位安全位置，请检查");
                                break;
                            }
                            //TODO X轴移动到放料位
                            pp = Machine.pos_Lrock2PutPos_Lstation5.Clone();
                            pp.isShowY2Position = true;
                            pp.isShowZ6Position = false;
                            pp.AxisPriority = "1";
                            if (MotionControl.AxesMove(pp) == true)
                            {
                                pp = Machine.pos_Lrock2PutPos_Lstation5.Clone();
                                pp.isShowY2Position = false;
                                pp.isShowZ6Position = true;
                                pp.AxisPriority = "1";
                                if (MotionControl.AxesMove(pp) == true)
                                {
                                    Machine.do_量测左搬运工位后吸嘴吸.ON();
                                    Thread.Sleep(500);
                                    Machine.do_量测左定位机构载盘吸嘴吸.OFF();
                                    Machine.do_量测左上CCD载盘吸嘴吸.OFF();
                                    Machine.do_量测左上激光载盘吸嘴吸.OFF();
                                    Machine.do_量测左CCD旋转工位吸嘴吸.OFF();
                                    Thread.Sleep(200);
                                    Step1 = Step1 + 1;
                                }
                            }
                            break;

                        case 45: //摆臂到安全位置   
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LlaserInitialPos_Lstation7.X2AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X3初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LccdInitialPos_Lstation6.Z5AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ15初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在负限位安全位置，请检查");
                                break;
                            }
                            pp = Machine.pos_LrockSaftPos_Lstation5.Clone();
                            pp.isShowY2Position = false;
                            pp.isShowZ6Position = true;
                            pp.AxisPriority = "1";
                            if (MotionControl.AxesMove(pp) == true)
                            {
                                //if (MotionControl.AxesMove(Machine.pos_LrockSaftPos_Lstation5))
                                //{
                                Step1 = Step1 + 1;
                                //}
                            }
                            break;

                        case 46: //摆臂到取料位置
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LlaserInitialPos_Lstation7.X2AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X3初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LccdInitialPos_Lstation6.Z5AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ15初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在负限位安全位置，请检查");
                                break;
                            }

                            pp = Machine.pos_LrockInitialPos_Lstation5.Clone();
                            pp.isShowY2Position = false;
                            pp.isShowZ6Position = true;
                            pp.AxisPriority = "1";
                            if (MotionControl.AxesMove(pp) == true)
                            {
                                //走Y
                                pp = Machine.pos_Lrock2FetchPos_Lstation5.Clone();
                                pp.isShowY2Position = true;
                                pp.isShowZ6Position = false;
                                pp.AxisPriority = "1";
                                if (MotionControl.AxesMove(pp) == true)
                                {
                                    //走Z
                                    pp = Machine.pos_Lrock2FetchPos_Lstation5.Clone();
                                    pp.isShowY2Position = false;
                                    pp.isShowZ6Position = true;
                                    pp.AxisPriority = "1";
                                    if (MotionControl.AxesMove(pp))
                                    {
                                        Machine.do_量测左上激光载盘吸嘴吸.ON();
                                        Thread.Sleep(500);
                                        Machine.do_量测左搬运工位前吸嘴吸.OFF();
                                        Machine.do_量测左搬运工位中吸嘴吸.OFF();
                                        Machine.do_量测左搬运工位后吸嘴吸.OFF();
                                        Thread.Sleep(200);
                                        Step1 = Step1 + 1;
                                    }
                                }
                            }
                            break;

                        case 47: //摆臂Z轴提升到安全位置
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LlaserInitialPos_Lstation7.X2AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X3初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LccdInitialPos_Lstation6.Z5AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ15初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在负限位安全位置，请检查");
                                break;
                            }
                            pp = Machine.pos_LrockInitialPos_Lstation5.Clone();
                            pp.isShowY2Position = false;
                            pp.isShowZ6Position = true;
                            pp.AxisPriority = "1";
                            if (MotionControl.AxesMove(pp) == true)
                            {
                                Step1 = Step1 + 1;
                            }
                            break;
                        #endregion

                        #region 第二次返回
                        case 48: //摆臂到放料位置   关闭摆臂真空   打开量测真空吸
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LlaserInitialPos_Lstation7.X2AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X3初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LccdInitialPos_Lstation6.Z5AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ15初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在负限位安全位置，请检查");
                                break;
                            }
                            //TODO X轴移动到放料位
                            pp = Machine.pos_Lrock2PutPos_Lstation5.Clone();
                            pp.isShowY2Position = true;
                            pp.isShowZ6Position = false;
                            pp.AxisPriority = "1";
                            if (MotionControl.AxesMove(pp) == true)
                            {
                                pp = Machine.pos_Lrock2PutPos_Lstation5.Clone();
                                pp.isShowY2Position = false;
                                pp.isShowZ6Position = true;
                                pp.AxisPriority = "1";
                                if (MotionControl.AxesMove(pp) == true)
                                {
                                    Machine.do_量测左搬运工位中吸嘴吸.ON();
                                    Thread.Sleep(500);
                                    Machine.do_量测左定位机构载盘吸嘴吸.OFF();
                                    Machine.do_量测左上CCD载盘吸嘴吸.OFF();
                                    Machine.do_量测左上激光载盘吸嘴吸.OFF();
                                    Machine.do_量测左CCD旋转工位吸嘴吸.OFF();
                                    Thread.Sleep(200);
                                    Step1 = Step1 + 1;
                                }
                            }
                            break;

                        case 49: //摆臂到安全位置   
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LlaserInitialPos_Lstation7.X2AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X3初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LccdInitialPos_Lstation6.Z5AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ15初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在负限位安全位置，请检查");
                                break;
                            }
                            pp = Machine.pos_LrockSaftPos_Lstation5.Clone();
                            pp.isShowY2Position = false;
                            pp.isShowZ6Position = true;
                            pp.AxisPriority = "1";
                            if (MotionControl.AxesMove(pp) == true)
                            {
                                //if (MotionControl.AxesMove(Machine.pos_LrockSaftPos_Lstation5))
                                //{
                                Step1 = Step1 + 1;
                                //}
                            }
                            break;

                        case 50: //摆臂到取料位置
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LlaserInitialPos_Lstation7.X2AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X3初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LccdInitialPos_Lstation6.Z5AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ15初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在负限位安全位置，请检查");
                                break;
                            }

                            pp = Machine.pos_LrockInitialPos_Lstation5.Clone();
                            pp.isShowY2Position = false;
                            pp.isShowZ6Position = true;
                            pp.AxisPriority = "1";
                            if (MotionControl.AxesMove(pp) == true)
                            {
                                //走Y
                                pp = Machine.pos_Lrock2FetchPos_Lstation5.Clone();
                                pp.isShowY2Position = true;
                                pp.isShowZ6Position = false;
                                pp.AxisPriority = "1";
                                if (MotionControl.AxesMove(pp) == true)
                                {
                                    //走Z
                                    pp = Machine.pos_Lrock2FetchPos_Lstation5.Clone();
                                    pp.isShowY2Position = false;
                                    pp.isShowZ6Position = true;
                                    pp.AxisPriority = "1";
                                    if (MotionControl.AxesMove(pp))
                                    {
                                        Machine.do_量测左上CCD载盘吸嘴吸.ON();
                                        Thread.Sleep(500);

                                        Machine.do_量测左搬运工位前吸嘴吸.OFF();
                                        Machine.do_量测左搬运工位中吸嘴吸.OFF();
                                        Machine.do_量测左搬运工位后吸嘴吸.OFF();
                                        Thread.Sleep(200);


                                        Step1 = Step1 + 1;
                                    }
                                }
                            }
                            break;

                        case 51: //摆臂Z轴提升到安全位置
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LlaserInitialPos_Lstation7.X2AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X3初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LccdInitialPos_Lstation6.Z5AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ15初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在负限位安全位置，请检查");
                                break;
                            }
                            pp = Machine.pos_LrockInitialPos_Lstation5.Clone();
                            pp.isShowY2Position = false;
                            pp.isShowZ6Position = true;
                            pp.AxisPriority = "1";
                            if (MotionControl.AxesMove(pp) == true)
                            {
                                Step1 = Step1 + 1;
                            }
                            break;
                        #endregion

                        #region 第三次返回
                        case 52: //摆臂到放料位置   关闭摆臂真空   打开量测真空吸
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LlaserInitialPos_Lstation7.X2AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X3初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LccdInitialPos_Lstation6.Z5AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ15初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在负限位安全位置，请检查");
                                break;
                            }
                            //TODO X轴移动到放料位
                            pp = Machine.pos_Lrock2PutPos_Lstation5.Clone();
                            pp.isShowY2Position = true;
                            pp.isShowZ6Position = false;
                            pp.AxisPriority = "1";
                            if (MotionControl.AxesMove(pp) == true)
                            {
                                pp = Machine.pos_Lrock2PutPos_Lstation5.Clone();
                                pp.isShowY2Position = false;
                                pp.isShowZ6Position = true;
                                pp.AxisPriority = "1";
                                if (MotionControl.AxesMove(pp) == true)
                                {
                                    Machine.do_量测左搬运工位前吸嘴吸.ON();
                                    Thread.Sleep(500);
                                    Machine.do_量测左定位机构载盘吸嘴吸.OFF();
                                    Machine.do_量测左上CCD载盘吸嘴吸.OFF();
                                    Machine.do_量测左上激光载盘吸嘴吸.OFF();
                                    Machine.do_量测左CCD旋转工位吸嘴吸.OFF();
                                    Thread.Sleep(200);
                                    Step1 = Step1 + 1;
                                }
                            }
                            break;

                        case 53: //摆臂到安全位置   
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LlaserInitialPos_Lstation7.X2AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X3初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LccdInitialPos_Lstation6.Z5AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ15初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在负限位安全位置，请检查");
                                break;
                            }
                            pp = Machine.pos_LrockSaftPos_Lstation5.Clone();
                            pp.isShowY2Position = false;
                            pp.isShowZ6Position = true;
                            pp.AxisPriority = "1";
                            if (MotionControl.AxesMove(pp) == true)
                            {
                                //if (MotionControl.AxesMove(Machine.pos_LrockSaftPos_Lstation5))
                                //{
                                Step1 = Step1 + 1;
                                //}
                            }
                            break;

                        case 54: //摆臂到取料位置
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LlaserInitialPos_Lstation7.X2AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X3初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LccdInitialPos_Lstation6.Z5AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ15初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在负限位安全位置，请检查");
                                break;
                            }


                            Machine.do_量测左定位机构定位气缸伸出.ON();
                            Machine.do_量测左定位机构定位气缸缩回.OFF();

                            pp = Machine.pos_LrockInitialPos_Lstation5.Clone();
                            pp.isShowY2Position = false;
                            pp.isShowZ6Position = true;
                            pp.AxisPriority = "1";
                            if (MotionControl.AxesMove(pp) == true)
                            {
                                //走Y
                                pp = Machine.pos_Lrock2FetchPos_Lstation5.Clone();
                                pp.isShowY2Position = true;
                                pp.isShowZ6Position = false;
                                pp.AxisPriority = "1";
                                if (MotionControl.AxesMove(pp) == true)
                                {
                                    //走Z
                                    pp = Machine.pos_Lrock2FetchPos_Lstation5.Clone();
                                    pp.isShowY2Position = false;
                                    pp.isShowZ6Position = true;
                                    pp.AxisPriority = "1";
                                    if (MotionControl.AxesMove(pp))
                                    {
                                        Machine.do_量测左定位机构载盘吸嘴吸.ON();
                                        Thread.Sleep(500);

                                        Machine.do_量测左搬运工位前吸嘴吸.OFF();
                                        Machine.do_量测左搬运工位中吸嘴吸.OFF();
                                        Machine.do_量测左搬运工位后吸嘴吸.OFF();
                                        Thread.Sleep(200);

                                        Step1 = Step1 + 1;
                                    }
                                }
                            }
                            break;

                        case 55: //摆臂Z轴提升到安全位置
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LlaserInitialPos_Lstation7.X2AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X3初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LccdInitialPos_Lstation6.Z5AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ15初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在负限位安全位置，请检查");
                                break;
                            }
                            pp = Machine.pos_LrockInitialPos_Lstation5.Clone();
                            pp.isShowY2Position = false;
                            pp.isShowZ6Position = true;
                            pp.AxisPriority = "1";
                            if (MotionControl.AxesMove(pp) == true)
                            {
                                pp = Machine.pos_LrockInitialPos_Lstation5.Clone();
                                pp.isShowY2Position = true;
                                pp.isShowZ6Position = false;
                                pp.AxisPriority = "1";
                                if (MotionControl.AxesMove(pp) == true)
                                {
                                    Step1 = Step1 + 1;
                                }
                            }
                            break;
                        #endregion

                        case 56: //摆臂返回OK    判断循环次数
                            LgrrCount++;
                            if (LgrrCount == Common.LeftGrrCount)
                            {
                                LgrrCount = 0;
                                Machine.do_量测左定位机构载盘吸嘴吸.OFF();
                                MessageBox.Show("左Grr完成，请取出料");
                                LeftGrrIng = false;
                                Step1 = 1;
                                return;
                            }
                            else
                            {
                                Step1 = 2;
                            }

                            break;
                    }
                }
            }
        }
        private void RightGrr()
        {
            RightGrrIng = true;
            while (true)
            {
                Thread.Sleep(10);
                if (MachineStatusManager.CurrentMachineStatus == MachineStatus.Running)
                {
                    switch (Step2)
                    {
                        case 1:
                            //等待人工放料
                            while (Right_MeasurementLocation.GrrPutProduct == false)
                            {
                                Thread.Sleep(5);
                            }
                            Right_MeasurementLocation.GrrPutProduct = false;
                            Step2 = Step2 + 1;
                            break;

                        case 2: //定位工站吸   定位
                            Machine.do_量测右定位机构载盘吸嘴吸.ON();
                            Machine.do_量测右定位机构定位气缸伸出.OFF();
                            Machine.do_量测右定位机构定位气缸缩回.ON();
                            Thread.Sleep(500);
                            Step2 = Step2 + 1;
                            break;

                        case 3: //摆臂到取料位置   打开摆臂吸气     关闭量测真空   
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RlaserInitialPos_Rstation7.X4AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X4初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RccdInitialPos_Rstation6.Z11AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ14初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在负限位安全位置，请检查");
                                break;
                            }

                            //抬升安全Z
                            Rpp = Machine.pos_RrockInitialPos_Rstation5.Clone();
                            Rpp.isShowY4Position = false;
                            Rpp.isShowZ12Position = true;
                            Rpp.AxisPriority = "1";
                            if (MotionControl.AxesMove(Rpp) == true)
                            {
                                //走Y
                                Rpp = Machine.pos_Rrock2FetchPos_Rstation5.Clone();
                                Rpp.isShowY4Position = true;
                                Rpp.isShowZ12Position = false;
                                Rpp.AxisPriority = "1";
                                if (MotionControl.AxesMove(Rpp) == true)
                                {
                                    //走Z
                                    Rpp = Machine.pos_Rrock2FetchPos_Rstation5.Clone();
                                    Rpp.isShowY4Position = false;
                                    Rpp.isShowZ12Position = true;
                                    Rpp.AxisPriority = "1";
                                    if (MotionControl.AxesMove(Rpp) == true)
                                    {
                                        Machine.do_量测右搬运工位前吸嘴吸.ON();
                                        Thread.Sleep(500);

                                        Machine.do_量测右定位机构定位气缸伸出.ON();
                                        Machine.do_量测右定位机构定位气缸缩回.OFF();

                                        Machine.do_量测右定位机构载盘吸嘴吸.OFF();
                                        Machine.do_量测右上CCD载盘吸嘴吸.OFF();
                                        Machine.do_量测右上激光载盘吸嘴吸.OFF();
                                        Machine.do_量测右CCD旋转工位吸嘴吸.OFF();
                                        Thread.Sleep(200);
                                        Step2 = Step2 + 1;
                                    }
                                }
                            }
                            break;

                        case 4: //摆臂Z轴提升到安全位置
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RlaserInitialPos_Rstation7.X4AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X4初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RccdInitialPos_Rstation6.Z11AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ14初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在负限位安全位置，请检查");
                                break;
                            }
                            Rpp = Machine.pos_RrockInitialPos_Rstation5.Clone();
                            Rpp.isShowY4Position = false;
                            Rpp.isShowZ12Position = true;
                            Rpp.AxisPriority = "1";
                            if (MotionControl.AxesMove(Rpp) == true)
                            {
                                Step2 = Step2 + 1;
                            }
                            break;

                        case 5: //摆臂到放料位置   关闭摆臂真空   打开量测真空吸
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RlaserInitialPos_Rstation7.X4AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X4初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RccdInitialPos_Rstation6.Z11AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ14初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在负限位安全位置，请检查");
                                break;
                            }
                            //TODO X轴移动到放料位
                            Rpp = Machine.pos_Rrock2PutPos_Rstation5.Clone();
                            Rpp.isShowY4Position = true;
                            Rpp.isShowZ12Position = false;
                            Rpp.AxisPriority = "1";
                            if (MotionControl.AxesMove(Rpp) == true)
                            {
                                Rpp = Machine.pos_Rrock2PutPos_Rstation5.Clone();
                                Rpp.isShowY4Position = false;
                                Rpp.isShowZ12Position = true;
                                Rpp.AxisPriority = "1";
                                if (MotionControl.AxesMove(Rpp) == true)
                                {
                                    Machine.do_量测右搬运工位前吸嘴吸.OFF();
                                    Machine.do_量测右搬运工位中吸嘴吸.OFF();
                                    Machine.do_量测右搬运工位后吸嘴吸.OFF();
                                    Thread.Sleep(200);
                                    Machine.do_量测右CCD旋转工位吸嘴吸.ON();  ////激光
                                    Thread.Sleep(500);
                                    Step2 = Step2 + 1;
                                }
                            }
                            break;

                        case 6: //摆臂到安全位置     
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RlaserInitialPos_Rstation7.X4AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X4初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RccdInitialPos_Rstation6.Z11AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ14初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在负限位安全位置，请检查");
                                break;
                            }
                            Rpp = Machine.pos_RrockSaftPos_Rstation5.Clone();
                            Rpp.isShowY4Position = false;
                            Rpp.isShowZ12Position = true;
                            Rpp.AxisPriority = "1";
                            if (MotionControl.AxesMove(Rpp) == true)
                            {
                                if (MotionControl.AxesMove(Machine.pos_RrockSaftPos_Rstation5))
                                {
                                    Step2 = Step2 + 1;
                                }
                            }
                            break;

                        /////////////////////////////////上CCD拍照处理//////////////////////////////////////
                        #region 上CCD拍照处理
                        case 7:
                            if (MotionControl.AxesMove(Machine.pos_RccdMeasureBlockPos_Rstation6))
                            {
                                Step2 = Step2 + 1;
                            }
                            break;

                        case 8:   //拍照视觉处理                  //拍第一次背光，计算FAI1
                            if (Common.isPointCheckModel)//点检模式
                            {
                                /////////////////先判断是大 中 小 哪一类型的block////////////////////
                                Common.light2.WriteData(Common.lightList[(int)LIGHT_ENUM.右工位2上环光].Chanel, Common.lightList[(int)LIGHT_ENUM.右工位2上环光].Value);
                                Thread.Sleep(50);

                                string strLeftStation2_Radius = string.Empty;
                                Leng = new VisionPlatform.VisionManager.Engine("Station2_Capture_Radius");
                                Leng.ActionFun();
                                strLeftStation2_Radius = Leng.GetOutputString("CmdResult");
                                string[] str = strLeftStation2_Radius.Split(',');
                                strLeftStation2_Radius = str[2].Split(':')[1];
                                blockSN = str[1].Split(':')[1];

                                Common.light2.WriteData(Common.lightList[(int)LIGHT_ENUM.右工位2上环光].Chanel, 0);

                                if (strLeftStation2_Radius == "3")
                                {
                                    Common.ProductType = 3;//大
                                }
                                else if (strLeftStation2_Radius == "2")
                                {
                                    Common.ProductType = 2;//中
                                }
                                else if (strLeftStation2_Radius == "1")
                                {
                                    Common.ProductType = 1;//小
                                }
                                else
                                {
                                    MessageBox.Show("识别标准块错误");
                                }
                            }
                            else
                            {
                                Common.ProductType = -1;//正常产品
                            }

                            MotionControl.AxesMove(Machine.pos_LccdMeasurePos_Lstation6);
                            /////第一次拍照///////////////////
                            Common.light2.WriteData(Common.lightList[(int)LIGHT_ENUM.右工位2下背光].Chanel, Common.lightList[(int)LIGHT_ENUM.右工位2下背光].Value);
                            Thread.Sleep(50);
                            try
                            {
                                Leng = new VisionPlatform.VisionManager.Engine("Station2_Capture");
                                Leng.ActionFun();
                                string revStr0 = Leng.GetOutputString("CmdResult");

                                while (revStr0 != "Station2,1")
                                {
                                    Thread.Sleep(5);
                                }

                                Leng = null;
                            }
                            catch (System.Exception)
                            {
                                Common.AppendUiLog.Log("左工位2第一次拍照异常...", LogType.Error);
                            }
                            Common.light2.WriteData(Common.lightList[(int)LIGHT_ENUM.右工位2下背光].Chanel, 0);
                            Step2 = Step2 + 1;
                            break;

                        case 9:   //测量完成，Z轴移动到初始位置
                            if (MotionControl.AxesMove(Machine.pos_RccdInitialPos_Rstation6))
                            {
                                Step2 = Step2 + 1;
                            }
                            break;

                        case 10:   //等待视觉处理结果
                            string strLeftStation2 = string.Empty;
                            //发送要结果的指令
                            Machine.SecondComputerSocket.SendStr("Station2_Calculation" + Environment.NewLine);

                            while (Common.strStation1Ok == string.Empty)
                            {
                                Thread.Sleep(10);
                            }
                            strLeftStation2 = Common.strStation1Ok;
                            Common.strStation1Ok = string.Empty;

                            Common.AppendUiLog.Log(strLeftStation2, LogType.Alert);

                            //数据融合
                            string[] revData1 = strLeftStation2.Split(',');
                            MeasureProduct mp = new MeasureProduct();
                            for (int i = 0; i < revData1.Length; i++)
                            {
                                if (revData1[i].Contains(":"))
                                {
                                    string FAIName = revData1[i].Split(':')[0];
                                    string FAIValue = revData1[i].Split(':')[1];
                                    DataItem FAI = new DataItem();
                                    FAI.Name = FAIName;
                                    FAI.Value = double.Parse(FAIValue);
                                    FAI.Position = 0;
                                    mp.MeasureData.Add(FAI);
                                }
                            }
                            //数据入队
                            mp.whichBlock = Common.ProductTypeRight;
                            Common.Station2Queue_R.Enqueue(mp);
                            Step2 = Step2 + 1;
                            break;
                        #endregion

                        case 11: //摆臂到取料位置
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RlaserInitialPos_Rstation7.X4AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X4初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RccdInitialPos_Rstation6.Z11AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ14初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在负限位安全位置，请检查");
                                break;
                            }

                            //抬升安全Z
                            Rpp = Machine.pos_RrockInitialPos_Rstation5.Clone();
                            Rpp.isShowY4Position = false;
                            Rpp.isShowZ12Position = true;
                            Rpp.AxisPriority = "1";
                            if (MotionControl.AxesMove(Rpp) == true)
                            {
                                //走Y
                                Rpp = Machine.pos_Rrock2FetchPos_Rstation5.Clone();
                                Rpp.isShowY4Position = true;
                                Rpp.isShowZ12Position = false;
                                Rpp.AxisPriority = "1";
                                if (MotionControl.AxesMove(Rpp) == true)
                                {
                                    //走Z
                                    Rpp = Machine.pos_Rrock2FetchPos_Rstation5.Clone();
                                    Rpp.isShowY4Position = false;
                                    Rpp.isShowZ12Position = true;
                                    Rpp.AxisPriority = "1";
                                    if (MotionControl.AxesMove(Rpp) == true)
                                    {
                                        Machine.do_量测右搬运工位中吸嘴吸.ON();
                                        Thread.Sleep(500);
                                        Machine.do_量测右定位机构载盘吸嘴吸.OFF();
                                        Machine.do_量测右上CCD载盘吸嘴吸.OFF();
                                        Machine.do_量测右上激光载盘吸嘴吸.OFF();
                                        Machine.do_量测右CCD旋转工位吸嘴吸.OFF();
                                        Thread.Sleep(200);
                                        Step2 = Step2 + 1;
                                    }
                                }
                            }
                            break;

                        case 12: //摆臂Z轴提升到安全位置
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RlaserInitialPos_Rstation7.X4AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X4初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RccdInitialPos_Rstation6.Z11AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ14初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在负限位安全位置，请检查");
                                break;
                            }
                            Rpp = Machine.pos_RrockInitialPos_Rstation5.Clone();
                            Rpp.isShowY4Position = false;
                            Rpp.isShowZ12Position = true;
                            Rpp.AxisPriority = "1";
                            if (MotionControl.AxesMove(Rpp) == true)
                            {
                                Step2 = Step2 + 1;
                            }
                            break;

                        #region 下CCD拍照处理
                        case 13:  //如果需要下CCD拍照则移动到下CCD 拍照位置  
                            if (MotionControl.AxesMove(Machine.pos_Rrock2BottomCCDPos_Rstation5))
                            {
                                Step2 = Step2 + 1;
                            }
                            break;

                        case 14:
                            string strLeftStation3 = string.Empty;
                            Common.light3.WriteData(Common.lightList[(int)LIGHT_ENUM.右工位3下同轴光SN].Chanel, Common.lightList[(int)LIGHT_ENUM.右工位3下同轴光SN].Value);
                            Thread.Sleep(50);
                            ///第一次拍照
                            try
                            {
                                Leng = new VisionPlatform.VisionManager.Engine("Station3_Capture");
                                Leng.SetInputString("Index", "1");
                                Leng.SetInputNumber("Type", Common.ProductType);
                                Leng.ActionFun();
                                strLeftStation3 = Leng.GetOutputString("CmdResult");

                                while (strLeftStation3 != "Station3,1")
                                {
                                    Thread.Sleep(5);
                                }
                                Common.AppendUiLog.Log(strLeftStation3, LogType.Alert);
                                strLeftStation3 = string.Empty;

                                Leng = null;
                            }
                            catch
                            {
                                Common.AppendUiLog.Log("左工位3第一次拍照异常...", LogType.Error);
                            }
                            Common.light3.WriteData(Common.lightList[(int)LIGHT_ENUM.右工位3下同轴光SN].Chanel,0);

                            ///第2次拍照
                            Common.light3.WriteData(Common.lightList[(int)LIGHT_ENUM.右工位3下同轴光].Chanel, Common.lightList[(int)LIGHT_ENUM.右工位3下同轴光].Value);
                            Thread.Sleep(50);
                            try
                            {
                                Leng = new VisionPlatform.VisionManager.Engine("Station3_Capture");
                                Leng.SetInputString("Index", "2");
                                Leng.SetInputNumber("Type", Common.ProductType);
                                Leng.ActionFun();
                                strLeftStation3 = Leng.GetOutputString("CmdResult");

                                while (strLeftStation3 != "Station3,2")
                                {
                                    Thread.Sleep(5);
                                }
                                Common.AppendUiLog.Log(strLeftStation3, LogType.Alert);

                                strLeftStation3 = string.Empty;

                                Leng = null;
                            }
                            catch
                            {
                                Common.AppendUiLog.Log("左工位3第2次拍照异常...", LogType.Error);
                            }
                            Common.light3.WriteData(Common.lightList[(int)LIGHT_ENUM.右工位3下同轴光].Chanel,0);

                            ///第3次拍照
                            Common.light3.WriteData(Common.lightList[(int)LIGHT_ENUM.右工位3下同轴光2].Chanel, Common.lightList[(int)LIGHT_ENUM.右工位3下同轴光2].Value);
                            Thread.Sleep(50);
                            try
                            {
                                Leng = new VisionPlatform.VisionManager.Engine("Station3_Capture");
                                Leng.SetInputString("Index", "3");
                                Leng.SetInputNumber("Type", Common.ProductType);
                                Leng.ActionFun();
                                strLeftStation3 = Leng.GetOutputString("CmdResult");

                                while (strLeftStation3 != "Station3,3")
                                {
                                    Thread.Sleep(5);
                                }
                                Common.AppendUiLog.Log(strLeftStation3, LogType.Alert);

                                strLeftStation3 = string.Empty;

                                Leng = null;
                            }
                            catch
                            {
                                Common.AppendUiLog.Log("左工位3第3次拍照异常...", LogType.Error);
                            }

                            Common.light3.WriteData(Common.lightList[(int)LIGHT_ENUM.右工位3下同轴光2].Chanel, 0);

                            ///////接受量测值
                            Thread.Sleep(50);
                            try
                            {
                                //不同类型产品调用不同的算法
                                if (Common.ProductType == -1)
                                {
                                    Leng = new VisionPlatform.VisionManager.Engine("Station3");
                                }
                                else if (Common.ProductType == 1)
                                {
                                    Leng = new VisionPlatform.VisionManager.Engine("Station3_Min");
                                }
                                else if (Common.ProductType == 2)
                                {
                                    Leng = new VisionPlatform.VisionManager.Engine("Station3_Mid");
                                }
                                else if (Common.ProductType == 3)
                                {
                                    Leng = new VisionPlatform.VisionManager.Engine("Station3_Max");
                                }
                                Leng.ActionFun();
                                strLeftStation3 = Leng.GetOutputString("Station3Result");
                                Leng = null;
                            }
                            catch
                            {
                                //strLeftStation3 = "LeftStation3OK" + "," + "SN:" + "Test";
                            }

                            //数据融合
                            string[] revData13 = strLeftStation3.Split(',');
                            MeasureProduct mp3 = new MeasureProduct();
                            Common.Station2Queue_R.TryDequeue(out mp3);
                            for (int i = 0; i < revData13.Length; i++)
                            {
                                if (revData13[i].Contains(":"))
                                {
                                    string FAIName = revData13[i].Split(':')[0];
                                    string FAIValue = revData13[i].Split(':')[1];
                                    DataItem FAI = new DataItem();
                                    FAI.Name = FAIName;
                                    if (FAIName != "SN")
                                    {
                                        FAI.Value = double.Parse(FAIValue);
                                        FAI.Position = 0;
                                        mp3.MeasureData.Add(FAI);
                                    }
                                    else
                                    {
                                        if (Common.isPointCheckModel == false)
                                        {
                                            mp3.SN = FAIValue;
                                        }
                                        else
                                        {
                                            mp3.SN = blockSN;
                                        }
                                    }
                                }
                            }
                            //数据入队
                            Common.Station3Queue_R.Enqueue(mp3);
                            strLeftStation3 = string.Empty;
                            Step2 = Step2 + 1;
                            break;
                        #endregion

                        case 15: //摆臂到放料位置   关闭摆臂真空   打开量测真空吸
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RlaserInitialPos_Rstation7.X4AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X4初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RccdInitialPos_Rstation6.Z11AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ14初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在负限位安全位置，请检查");
                                break;
                            }
                            //TODO X轴移动到放料位
                            Rpp = Machine.pos_Rrock2PutPos_Rstation5.Clone();
                            Rpp.isShowY4Position = true;
                            Rpp.isShowZ12Position = false;
                            Rpp.AxisPriority = "1";
                            if (MotionControl.AxesMove(Rpp) == true)
                            {
                                Rpp = Machine.pos_Rrock2PutPos_Rstation5.Clone();
                                Rpp.isShowY4Position = false;
                                Rpp.isShowZ12Position = true;
                                Rpp.AxisPriority = "1";
                                if (MotionControl.AxesMove(Rpp) == true)
                                {
                                    Machine.do_量测右搬运工位前吸嘴吸.OFF();
                                    Machine.do_量测右搬运工位中吸嘴吸.OFF();
                                    Machine.do_量测右搬运工位后吸嘴吸.OFF();
                                    Thread.Sleep(200);
                                    Machine.do_量测右CCD旋转工位吸嘴吸.ON();  ////激光
                                    Thread.Sleep(500);
                                    Step2 = Step2 + 1;
                                }
                            }
                            break;

                        case 16: //摆臂到安全位置   
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RlaserInitialPos_Rstation7.X4AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X4初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RccdInitialPos_Rstation6.Z11AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ14初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在负限位安全位置，请检查");
                                break;
                            }
                            Rpp = Machine.pos_RrockSaftPos_Rstation5.Clone();
                            Rpp.isShowY4Position = false;
                            Rpp.isShowZ12Position = true;
                            Rpp.AxisPriority = "1";
                            if (MotionControl.AxesMove(Rpp) == true)
                            {
                                if (MotionControl.AxesMove(Machine.pos_RrockSaftPos_Rstation5))
                                {
                                    Step2 = Step2 + 1;
                                }
                            }
                            break;

                        #region 激光处理
                        case 17:  //移动到激光测试的初始位置
                            if (MotionControl.AxesMove(Machine.pos_RlaserStartPos_Rstation7))
                            {
                                Step2 = Step2 + 1;
                            }
                            break;

                        case 18:   //打开激光触发
                            HOperatorSet.GrabImageStart(Common.LMILeftAcqHandle, -1);
                            Machine.do_右工位点激光触发.ON();
                            Common.strStation4LaserStart = string.Empty;
                            Step2 = Step2 + 1;
                            break;

                        case 19:   //运动到激光测量终点位置
                            if (MotionControl.AxesMove(Machine.pos_RlaserEndPos_Rstation7))
                            {
                                Machine.do_右工位点激光触发.OFF();
                                Step2 = Step2 + 1;
                            }
                            break;

                        case 20:     //采图并关闭激光触发
                            try
                            {
                                HOperatorSet.GrabImageAsync(out LLaserImage, Common.LMILeftAcqHandle, -1);
                                Common.Gocator1.system.Stop();
                                Common.Gocator1.system.ClearData();
                            }
                            catch (Exception ex)
                            {

                            }
                            Step2 = Step2 + 1;
                            break;

                        case 21:    //激光处理
                            if (MotionControl.AxesMove(Machine.pos_RlaserInitialPos_Rstation7))//运动到安全位
                            {
                                string strLeftStation4 = string.Empty;
                                HImage image1 = new HImage();
                                HImage image2 = new HImage();
                                try
                                {
                                    //点检和正常产品算法一样
                                    Leng = new VisionPlatform.VisionManager.Engine("Station4");
                                    Leng.SetInputImage("Image_3D", new HImage(LLaserImage).Decompose3(out image1, out image2));
                                    Leng.ActionFun();
                                    strLeftStation4 = Leng.GetOutputString("Station4Result");
                                }
                                catch
                                {
                                    strLeftStation4 = "LeftLaserStop" + "," + "FAI2:" + 9999;
                                }

                                //数据拆分
                                Common.AppendUiLog.Log(strLeftStation4, LogType.Alert);
                                string[] revData14 = strLeftStation4.Split(',');
                                //数据融合
                                MeasureProduct mp4 = new MeasureProduct();
                                Common.Station3Queue_R.TryDequeue(out mp4);
                                for (int i = 0; i < revData14.Length; i++)
                                {
                                    if (revData14[i].Contains(":"))
                                    {
                                        string FAIName = revData14[i].Split(':')[0];
                                        string FAIValue = revData14[i].Split(':')[1];
                                        DataItem FAI = new DataItem();
                                        FAI.Name = FAIName;
                                        FAI.Value = double.Parse(FAIValue);
                                        FAI.Position = 0;
                                        mp4.MeasureData.Add(FAI);
                                    }
                                }
                                //数据入队
                                Common.Station4Queue_R.Enqueue(mp4);
                                Step2 = Step2 + 1;
                            }
                            break;

                        case 22: //等待激光处理结果并轴回到初始位
                            if (MotionControl.CheckMoveDone(Machine.pos_RlaserInitialPos_Rstation7))
                            {
                                Step2 = Step2 + 1;
                            }
                            break;
                        #endregion

                        case 23: //摆臂到取料位置
                            Thread.Sleep(500);
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RlaserInitialPos_Rstation7.X4AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X4初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RccdInitialPos_Rstation6.Z11AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ14初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在负限位安全位置，请检查");
                                break;
                            }

                            //抬升安全Z
                            Rpp = Machine.pos_RrockInitialPos_Rstation5.Clone();
                            Rpp.isShowY4Position = false;
                            Rpp.isShowZ12Position = true;
                            Rpp.AxisPriority = "1";
                            if (MotionControl.AxesMove(Rpp) == true)
                            {
                                //走Y
                                Rpp = Machine.pos_Rrock2FetchPos_Rstation5.Clone();
                                Rpp.isShowY4Position = true;
                                Rpp.isShowZ12Position = false;
                                Rpp.AxisPriority = "1";
                                if (MotionControl.AxesMove(Rpp) == true)
                                {
                                    //走Z
                                    Rpp = Machine.pos_Rrock2FetchPos_Rstation5.Clone();
                                    Rpp.isShowY4Position = false;
                                    Rpp.isShowZ12Position = true;
                                    Rpp.AxisPriority = "1";
                                    if (MotionControl.AxesMove(Rpp) == true)
                                    {
                                        Machine.do_量测右搬运工位后吸嘴吸.ON();
                                        Thread.Sleep(500);
                                        Machine.do_量测右定位机构载盘吸嘴吸.OFF();
                                        Machine.do_量测右上CCD载盘吸嘴吸.OFF();
                                        Machine.do_量测右上激光载盘吸嘴吸.OFF();
                                        Machine.do_量测右CCD旋转工位吸嘴吸.OFF();
                                        Thread.Sleep(200);
                                        Step2 = Step2 + 1;
                                    }
                                }
                            }
                            break;

                        case 24: //摆臂Z轴提升到安全位置
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RlaserInitialPos_Rstation7.X4AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X4初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RccdInitialPos_Rstation6.Z11AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ14初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在负限位安全位置，请检查");
                                break;
                            }
                            Rpp = Machine.pos_RrockInitialPos_Rstation5.Clone();
                            Rpp.isShowY4Position = false;
                            Rpp.isShowZ12Position = true;
                            Rpp.AxisPriority = "1";
                            if (MotionControl.AxesMove(Rpp) == true)
                            {
                                Step2 = Step2 + 1;
                            }
                            break;

                        case 25: //摆臂到放料位置   关闭摆臂真空   打开量测真空吸
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RlaserInitialPos_Rstation7.X4AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X4初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RccdInitialPos_Rstation6.Z11AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ14初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在负限位安全位置，请检查");
                                break;
                            }
                            //TODO X轴移动到放料位
                            Rpp = Machine.pos_Rrock2PutPos_Rstation5.Clone();
                            Rpp.isShowY4Position = true;
                            Rpp.isShowZ12Position = false;
                            Rpp.AxisPriority = "1";
                            if (MotionControl.AxesMove(Rpp) == true)
                            {
                                Rpp = Machine.pos_Rrock2PutPos_Rstation5.Clone();
                                Rpp.isShowY4Position = false;
                                Rpp.isShowZ12Position = true;
                                Rpp.AxisPriority = "1";
                                if (MotionControl.AxesMove(Rpp) == true)
                                {
                                    Machine.do_量测右搬运工位前吸嘴吸.OFF();
                                    Machine.do_量测右搬运工位中吸嘴吸.OFF();
                                    Machine.do_量测右搬运工位后吸嘴吸.OFF();
                                    Thread.Sleep(200);
                                    Machine.do_量测右CCD旋转工位吸嘴吸.ON();  ////激光
                                    Thread.Sleep(500);
                                    Step2 = Step2 + 1;
                                }
                            }
                            break;

                        case 26: //摆臂到安全位置   
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RlaserInitialPos_Rstation7.X4AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X4初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RccdInitialPos_Rstation6.Z11AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ14初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在负限位安全位置，请检查");
                                break;
                            }
                            Rpp = Machine.pos_RrockSaftPos_Rstation5.Clone();
                            Rpp.isShowY4Position = false;
                            Rpp.isShowZ12Position = true;
                            Rpp.AxisPriority = "1";
                            if (MotionControl.AxesMove(Rpp) == true)
                            {
                                if (MotionControl.AxesMove(Machine.pos_RrockSaftPos_Rstation5))
                                {
                                    Step2 = Step2 + 1;
                                }
                            }
                            break;

                        #region 旋转工位拍照计算
                        case 27:
                            //TODO 旋转45°
                            if (MotionControl.AxesMove(Machine.pos_Rrotate1Pos_Rstation8) == true)
                            {
                                Step2 = Step2 + 1;
                            }
                            break;

                        case 28:  //第一次拍照
                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.右工位5侧背光].Chanel, Common.lightList[(int)LIGHT_ENUM.右工位5侧背光].Value);
                            Thread.Sleep(50);
                            string cord = string.Empty;
                            try
                            {
                                Leng = new VisionPlatform.VisionManager.Engine("Station5_Capture");
                                Leng.SetInputString("Index", "1");
                                Leng.SetInputNumber("Type", Common.ProductType);

                                Leng.ActionFun();
                                cord = Leng.GetOutputString("CmdResult");
                                Leng = null;
                            }
                            catch
                            {
                                cord = "Station5,1";
                                Common.AppendUiLog.Log("工位5第一次拍照异常...", LogType.Error);
                            }

                            while (cord != "Station5,1")
                            {
                                Thread.Sleep(5);
                            }

                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.右工位5侧背光].Chanel, 0);
                            Step2 = Step2 + 1;
                            break;

                        case 29:  //调用计算的视觉算子
                            try
                            {
                                //不同类型产品调用不同的算法
                                if (Common.ProductType == -1)
                                {
                                    Leng_Cal_1 = new VisionPlatform.VisionManager.Engine("Station5");
                                }
                                else if (Common.ProductType == 1)
                                {
                                    Leng_Cal_1 = new VisionPlatform.VisionManager.Engine("Station5_Min");
                                }
                                else if (Common.ProductType == 2)
                                {
                                    Leng_Cal_1 = new VisionPlatform.VisionManager.Engine("Station5_Mid");
                                }
                                else if (Common.ProductType == 3)
                                {
                                    Leng_Cal_1 = new VisionPlatform.VisionManager.Engine("Station5_Max");
                                }

                                Leng_Cal_1.SetInputString("Index", "1");
                                Leng_Cal_1.ActionFun();
                                cord = Leng_Cal_1.GetOutputString("StationResult");
                            }
                            catch
                            {
                                //cord = "Station5,1";
                                cord = "Finish,1";
                            }

                            while (cord != "Finish,1")
                            {
                                Thread.Sleep(5);
                            }

                            Step2 = Step2 + 1;
                            break;

                        case 30:
                            //TODO 旋转45°
                            if (MotionControl.AxesMove(Machine.pos_Rrotate2Pos_Rstation8) == true)
                            {
                                Step2 = Step2 + 1;
                            }
                            break;

                        case 31: //第二次拍照
                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.右工位5侧背光].Chanel, Common.lightList[(int)LIGHT_ENUM.右工位5侧背光].Value);
                            Thread.Sleep(50);
                            cord = string.Empty;
                            try
                            {
                                Leng = new VisionPlatform.VisionManager.Engine("Station5_Capture");
                                Leng.SetInputString("Index", "2");
                                Leng.SetInputNumber("Type", Common.ProductType);

                                Leng.ActionFun();
                                cord = Leng.GetOutputString("CmdResult");
                                Leng = null;
                            }
                            catch
                            {
                                cord = "Station5_2";
                                Common.AppendUiLog.Log("工位5第二次拍照异常...", LogType.Error);
                            }

                            while (cord != "Station5,2")
                            {
                                Thread.Sleep(5);
                            }
                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.右工位5侧背光].Chanel, 0);
                            Step2 = Step2 + 1;
                            break;

                        case 32:
                            try
                            {
                                if (Common.ProductType == -1)
                                {
                                    Leng_Cal_2 = new VisionPlatform.VisionManager.Engine("Station5");
                                }
                                else if (Common.ProductType == 1)
                                {
                                    Leng_Cal_2 = new VisionPlatform.VisionManager.Engine("Station5_Min");
                                }
                                else if (Common.ProductType == 2)
                                {
                                    Leng_Cal_2 = new VisionPlatform.VisionManager.Engine("Station5_Mid");
                                }
                                else if (Common.ProductType == 3)
                                {
                                    Leng_Cal_2 = new VisionPlatform.VisionManager.Engine("Station5_Max");
                                }

                                Leng_Cal_2.SetInputString("Index", "2");
                                Leng_Cal_2.ActionFun();
                                cord = Leng_Cal_2.GetOutputString("StationResult");
                            }
                            catch
                            {
                                cord = "Finish,2";
                            }

                            while (cord != "Finish,2")
                            {
                                Thread.Sleep(5);
                            }

                            Step2 = Step2 + 1;
                            break;

                        case 33:
                            //TODO 旋转45°
                            if (MotionControl.AxesMove(Machine.pos_Rrotate3Pos_Rstation8) == true)
                            {
                                Step2 = Step2 + 1;
                            }
                            break;

                        case 34:  //第三次拍照
                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.右工位5侧背光].Chanel, Common.lightList[(int)LIGHT_ENUM.右工位5侧背光].Value);
                            Thread.Sleep(50);
                            cord = string.Empty;
                            try
                            {
                                Leng = new VisionPlatform.VisionManager.Engine("Station5_Capture");
                                Leng.SetInputString("Index", "3");
                                Leng.SetInputNumber("Type", Common.ProductType);

                                Leng.ActionFun();
                                cord = Leng.GetOutputString("CmdResult");
                                Leng = null;
                            }
                            catch
                            {
                                cord = "Station5,3";
                            }

                            while (cord != "Station5,3")
                            {
                                Thread.Sleep(5);
                            }
                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.右工位5侧背光].Chanel, 0);
                            Step2 = Step2 + 1;
                            break;

                        case 35:
                            try
                            {
                                if (Common.ProductType == -1)
                                {
                                    Leng_Cal_3 = new VisionPlatform.VisionManager.Engine("Station5");
                                }
                                else if (Common.ProductType == 1)
                                {
                                    Leng_Cal_3 = new VisionPlatform.VisionManager.Engine("Station5_Min");
                                }
                                else if (Common.ProductType == 2)
                                {
                                    Leng_Cal_3 = new VisionPlatform.VisionManager.Engine("Station5_Mid");
                                }
                                else if (Common.ProductType == 3)
                                {
                                    Leng_Cal_3 = new VisionPlatform.VisionManager.Engine("Station5_Max");
                                }

                                Leng_Cal_3.SetInputString("Index", "3");
                                Leng_Cal_3.ActionFun();
                                cord = Leng_Cal_3.GetOutputString("StationResult");
                            }
                            catch
                            {
                                cord = "Finish,3";
                            }

                            while (cord != "Finish,3")
                            {
                                Thread.Sleep(5);
                            }

                            Step2 = Step2 + 1;
                            break;

                        case 36:
                            //TODO 旋转45°
                            if (MotionControl.AxesMove(Machine.pos_Rrotate4Pos_Rstation8) == true)
                            {
                                Step2 = Step2 + 1;
                            }
                            break;

                        case 37:// 第4次拍照
                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.右工位5侧背光].Chanel, Common.lightList[(int)LIGHT_ENUM.右工位5侧背光].Value);
                            Thread.Sleep(50);
                            cord = string.Empty;
                            try
                            {
                                Leng = new VisionPlatform.VisionManager.Engine("Station5_Capture");
                                Leng.SetInputString("Index", "4");
                                Leng.SetInputNumber("Type", Common.ProductType);

                                Leng.ActionFun();
                                cord = Leng.GetOutputString("CmdResult");
                                Leng = null;
                            }
                            catch
                            {
                                cord = "Station5,4";
                            }

                            while (cord != "Station5,4")
                            {
                                Thread.Sleep(5);
                            }
                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.右工位5侧背光].Chanel, 0);
                            Step2 = Step2 + 1;
                            break;

                        case 38:
                            try
                            {
                                if (Common.ProductType == -1)
                                {
                                    Leng_Cal_4 = new VisionPlatform.VisionManager.Engine("Station5");
                                }
                                else if (Common.ProductType == 1)
                                {
                                    Leng_Cal_4 = new VisionPlatform.VisionManager.Engine("Station5_Min");
                                }
                                else if (Common.ProductType == 2)
                                {
                                    Leng_Cal_4 = new VisionPlatform.VisionManager.Engine("Station5_Mid");
                                }
                                else if (Common.ProductType == 3)
                                {
                                    Leng_Cal_4 = new VisionPlatform.VisionManager.Engine("Station5_Max");
                                }
                                Leng_Cal_4.SetInputString("Index", "4");
                                Leng_Cal_4.ActionFun();
                                cord = Leng_Cal_4.GetOutputString("StationResult");
                            }
                            catch
                            {
                                cord = "Finish,4";
                            }

                            while (cord != "Finish,4")
                            {
                                Thread.Sleep(5);
                            }
                            Step2 = Step2 + 1;
                            break;

                        case 39:    //旋转轴转到初始位置
                            MotionControl.AxesMoveNoWait(Machine.pos_RrotateInitialPos_Rstation8);//异步运动到安全位
                            Step2 = Step2 + 1;
                            break;

                        case 40:
                            string strLeftStation5 = string.Empty;

                            while (Leng_Cal_1.GetOutputString("StationResult") != "Finish,1" || Leng_Cal_2.GetOutputString("StationResult") != "Finish,2"
                                        || Leng_Cal_3.GetOutputString("StationResult") != "Finish,3" || Leng_Cal_4.GetOutputString("StationResult") != "Finish,4")
                            {
                                Thread.Sleep(10);
                            }

                            Leng_Cal_1 = null;
                            Leng_Cal_2 = null;
                            Leng_Cal_3 = null;
                            Leng_Cal_4 = null;
                            try
                            {
                                Leng = new VisionPlatform.VisionManager.Engine("DataCaculate FAI3_9");
                                Leng.ActionFun();
                                strLeftStation5 = Leng.GetOutputString("Station5Result");
                            }
                            catch
                            {
                                strLeftStation5 = strLeftStation5 = "LeftStation3OK" + "," + "FAI5:" + 9999 + "," + "FAI6:" + 9999 + "," + "FAI7:" + 9999 + "," + "FAI8:" + 9999 + "," + "FAI9:" + 9999;
                            }

                            Common.AppendUiLog.Log(strLeftStation5, LogType.Alert);

                            //数据融合
                            string[] revData15 = strLeftStation5.Split(',');
                            MeasureProduct mp5 = new MeasureProduct();
                            Common.Station4Queue_R.TryDequeue(out mp5);
                            mp5.Position = "0";
                            for (int i = 0; i < revData15.Length; i++)
                            {
                                if (revData15[i].Contains(":"))
                                {
                                    string FAIName = revData15[i].Split(':')[0];
                                    string FAIValue = revData15[i].Split(':')[1];
                                    DataItem FAI = new DataItem();
                                    FAI.Name = FAIName;
                                    FAI.Value = double.Parse(FAIValue);
                                    FAI.Position = 0;
                                    mp5.MeasureData.Add(FAI);
                                }
                            }
                            //数据入队
                            Common.Station5Queue_R.Enqueue(mp5);
                            Step2 = Step2 + 1;
                            break;

                        case 41:      //整合产品的数据
                            MeasureProduct mp1 = new MeasureProduct();
                            Common.Station5Queue_R.TryDequeue(out mp1);

                            JUDGEMENT_RESULT ret = ProcessData.PrcessData(mp1);
                            RMergedDataFininshed = true;

                            if (ret == JUDGEMENT_RESULT.OK)
                            {
                                Machine.SecondComputerSocket.SendStr("ResultOK" + Environment.NewLine);
                            }
                            else
                            {
                                Machine.SecondComputerSocket.SendStr("ResultNG" + Environment.NewLine);
                            }

                            Step2 = Step2 + 1;
                            break;

                        case 42:   //等待旋转轴转到初始位置
                            if (MotionControl.CheckMoveDone(Machine.pos_RrotateInitialPos_Rstation8))
                            {
                                Step2 = Step2 + 1;
                            }
                            break;

                        case 43:    //等待数据整合完成
                            if (RMergedDataFininshed == true)
                            {
                                RMergedDataFininshed = false;
                                Step2 = Step2 + 1;
                            }
                            break;
                        #endregion

                        ///////////////////////////////////////开始返回/////////////////////////////////////////
                        #region 第一次返回
                        case 44: //摆臂到放料位置   关闭摆臂真空   打开量测真空吸
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RlaserInitialPos_Rstation7.X4AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X4初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RccdInitialPos_Rstation6.Z11AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ14初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在负限位安全位置，请检查");
                                break;
                            }
                            //TODO X轴移动到放料位
                            Rpp = Machine.pos_Rrock2PutPos_Rstation5.Clone();
                            Rpp.isShowY4Position = true;
                            Rpp.isShowZ12Position = false;
                            Rpp.AxisPriority = "1";
                            if (MotionControl.AxesMove(Rpp) == true)
                            {
                                Rpp = Machine.pos_Rrock2PutPos_Rstation5.Clone();
                                Rpp.isShowY4Position = false;
                                Rpp.isShowZ12Position = true;
                                Rpp.AxisPriority = "1";
                                if (MotionControl.AxesMove(Rpp) == true)
                                {
                                    Machine.do_量测右搬运工位后吸嘴吸.ON();
                                    Thread.Sleep(500);
                                    Machine.do_量测右定位机构载盘吸嘴吸.OFF();
                                    Machine.do_量测右上CCD载盘吸嘴吸.OFF();
                                    Machine.do_量测右上激光载盘吸嘴吸.OFF();
                                    Machine.do_量测右CCD旋转工位吸嘴吸.OFF();
                                    Thread.Sleep(200);

                                    Step2 = Step2 + 1;
                                }
                            }
                            break;

                        case 45: //摆臂到安全位置   
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RlaserInitialPos_Rstation7.X4AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X4初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RccdInitialPos_Rstation6.Z11AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ14初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在负限位安全位置，请检查");
                                break;
                            }
                            Rpp = Machine.pos_RrockSaftPos_Rstation5.Clone();
                            Rpp.isShowY4Position = false;
                            Rpp.isShowZ12Position = true;
                            Rpp.AxisPriority = "1";
                            if (MotionControl.AxesMove(Rpp) == true)
                            {
                                //if (MotionControl.AxesMove(Machine.pos_RrockSaftPos_Rstation5))
                                //{
                                Step2 = Step2 + 1;
                                //}
                            }
                            break;

                        case 46: //摆臂到取料位置
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RlaserInitialPos_Rstation7.X4AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X4初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RccdInitialPos_Rstation6.Z11AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ14初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在负限位安全位置，请检查");
                                break;
                            }

                            //抬升安全Z
                            Rpp = Machine.pos_RrockInitialPos_Rstation5.Clone();
                            Rpp.isShowY4Position = false;
                            Rpp.isShowZ12Position = true;
                            Rpp.AxisPriority = "1";
                            if (MotionControl.AxesMove(Rpp) == true)
                            {
                                //走Y
                                Rpp = Machine.pos_Rrock2FetchPos_Rstation5.Clone();
                                Rpp.isShowY4Position = true;
                                Rpp.isShowZ12Position = false;
                                Rpp.AxisPriority = "1";
                                if (MotionControl.AxesMove(Rpp) == true)
                                {
                                    //走Z
                                    Rpp = Machine.pos_Rrock2FetchPos_Rstation5.Clone();
                                    Rpp.isShowY4Position = false;
                                    Rpp.isShowZ12Position = true;
                                    Rpp.AxisPriority = "1";
                                    if (MotionControl.AxesMove(Rpp) == true)
                                    {
                                        Machine.do_量测右上激光载盘吸嘴吸.ON();
                                        Thread.Sleep(500);
                                        Machine.do_量测右搬运工位前吸嘴吸.OFF();
                                        Machine.do_量测右搬运工位中吸嘴吸.OFF();
                                        Machine.do_量测右搬运工位后吸嘴吸.OFF();
                                        Thread.Sleep(200);
                                        Step2 = Step2 + 1;
                                    }
                                }
                            }
                            break;

                        case 47: //摆臂Z轴提升到安全位置
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RlaserInitialPos_Rstation7.X4AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X4初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RccdInitialPos_Rstation6.Z11AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ14初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在负限位安全位置，请检查");
                                break;
                            }
                            Rpp = Machine.pos_RrockInitialPos_Rstation5.Clone();
                            Rpp.isShowY4Position = false;
                            Rpp.isShowZ12Position = true;
                            Rpp.AxisPriority = "1";
                            if (MotionControl.AxesMove(Rpp) == true)
                            {
                                Step2 = Step2 + 1;
                            }
                            break;
                        #endregion

                        #region 第二次返回
                        case 48: //摆臂到放料位置   关闭摆臂真空   打开量测真空吸
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RlaserInitialPos_Rstation7.X4AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X4初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RccdInitialPos_Rstation6.Z11AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ14初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在负限位安全位置，请检查");
                                break;
                            }
                            //TODO X轴移动到放料位
                            Rpp = Machine.pos_Rrock2PutPos_Rstation5.Clone();
                            Rpp.isShowY4Position = true;
                            Rpp.isShowZ12Position = false;
                            Rpp.AxisPriority = "1";
                            if (MotionControl.AxesMove(Rpp) == true)
                            {
                                Rpp = Machine.pos_Rrock2PutPos_Rstation5.Clone();
                                Rpp.isShowY4Position = false;
                                Rpp.isShowZ12Position = true;
                                Rpp.AxisPriority = "1";
                                if (MotionControl.AxesMove(Rpp) == true)
                                {
                                    Machine.do_量测右搬运工位中吸嘴吸.ON();
                                    Thread.Sleep(500);
                                    Machine.do_量测右定位机构载盘吸嘴吸.OFF();
                                    Machine.do_量测右上CCD载盘吸嘴吸.OFF();
                                    Machine.do_量测右上激光载盘吸嘴吸.OFF();
                                    Machine.do_量测右CCD旋转工位吸嘴吸.OFF();
                                    Thread.Sleep(200);
                                    Step2 = Step2 + 1;
                                }
                            }
                            break;

                        case 49: //摆臂到安全位置   
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RlaserInitialPos_Rstation7.X4AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X4初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RccdInitialPos_Rstation6.Z11AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ14初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在负限位安全位置，请检查");
                                break;
                            }
                            Rpp = Machine.pos_RrockSaftPos_Rstation5.Clone();
                            Rpp.isShowY4Position = false;
                            Rpp.isShowZ12Position = true;
                            Rpp.AxisPriority = "1";
                            if (MotionControl.AxesMove(Rpp) == true)
                            {
                                //if (MotionControl.AxesMove(Machine.pos_RrockSaftPos_Rstation5))
                                //{
                                Step2 = Step2 + 1;
                                //}
                            }
                            break;

                        case 50: //摆臂到取料位置
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RlaserInitialPos_Rstation7.X4AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X4初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RccdInitialPos_Rstation6.Z11AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ14初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在负限位安全位置，请检查");
                                break;
                            }

                            //抬升安全Z
                            Rpp = Machine.pos_RrockInitialPos_Rstation5.Clone();
                            Rpp.isShowY4Position = false;
                            Rpp.isShowZ12Position = true;
                            Rpp.AxisPriority = "1";
                            if (MotionControl.AxesMove(Rpp) == true)
                            {
                                //走Y
                                Rpp = Machine.pos_Rrock2FetchPos_Rstation5.Clone();
                                Rpp.isShowY4Position = true;
                                Rpp.isShowZ12Position = false;
                                Rpp.AxisPriority = "1";
                                if (MotionControl.AxesMove(Rpp) == true)
                                {
                                    //走Z
                                    Rpp = Machine.pos_Rrock2FetchPos_Rstation5.Clone();
                                    Rpp.isShowY4Position = false;
                                    Rpp.isShowZ12Position = true;
                                    Rpp.AxisPriority = "1";
                                    if (MotionControl.AxesMove(Rpp) == true)
                                    {
                                        Machine.do_量测右上CCD载盘吸嘴吸.ON();
                                        Thread.Sleep(500);
                                        Machine.do_量测右搬运工位前吸嘴吸.OFF();
                                        Machine.do_量测右搬运工位中吸嘴吸.OFF();
                                        Machine.do_量测右搬运工位后吸嘴吸.OFF();
                                        Thread.Sleep(200);
                                        Step2 = Step2 + 1;
                                    }
                                }
                            }
                            break;

                        case 51: //摆臂Z轴提升到安全位置
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RlaserInitialPos_Rstation7.X4AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X4初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RccdInitialPos_Rstation6.Z11AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ14初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在负限位安全位置，请检查");
                                break;
                            }
                            Rpp = Machine.pos_RrockInitialPos_Rstation5.Clone();
                            Rpp.isShowY4Position = false;
                            Rpp.isShowZ12Position = true;
                            Rpp.AxisPriority = "1";
                            if (MotionControl.AxesMove(Rpp) == true)
                            {
                                Step2 = Step2 + 1;
                            }
                            break;
                        #endregion

                        #region 第三次返回
                        case 52: //摆臂到放料位置   关闭摆臂真空   打开量测真空吸
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RlaserInitialPos_Rstation7.X4AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X4初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RccdInitialPos_Rstation6.Z11AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ14初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在负限位安全位置，请检查");
                                break;
                            }
                            //TODO X轴移动到放料位
                            Rpp = Machine.pos_Rrock2PutPos_Rstation5.Clone();
                            Rpp.isShowY4Position = true;
                            Rpp.isShowZ12Position = false;
                            Rpp.AxisPriority = "1";
                            if (MotionControl.AxesMove(Rpp) == true)
                            {
                                Rpp = Machine.pos_Rrock2PutPos_Rstation5.Clone();
                                Rpp.isShowY4Position = false;
                                Rpp.isShowZ12Position = true;
                                Rpp.AxisPriority = "1";
                                if (MotionControl.AxesMove(Rpp) == true)
                                {
                                    Machine.do_量测右搬运工位前吸嘴吸.ON();
                                    Thread.Sleep(500);
                                    Machine.do_量测右定位机构载盘吸嘴吸.OFF();
                                    Machine.do_量测右上CCD载盘吸嘴吸.OFF();
                                    Machine.do_量测右上激光载盘吸嘴吸.OFF();
                                    Machine.do_量测右CCD旋转工位吸嘴吸.OFF();
                                    Thread.Sleep(200);
                                    Step2 = Step2 + 1;
                                }
                            }
                            break;

                        case 53: //摆臂到安全位置   
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RlaserInitialPos_Rstation7.X4AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X4初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RccdInitialPos_Rstation6.Z11AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ14初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在负限位安全位置，请检查");
                                break;
                            }
                            Rpp = Machine.pos_RrockSaftPos_Rstation5.Clone();
                            Rpp.isShowY4Position = false;
                            Rpp.isShowZ12Position = true;
                            Rpp.AxisPriority = "1";
                            if (MotionControl.AxesMove(Rpp) == true)
                            {
                                //if (MotionControl.AxesMove(Machine.pos_RrockSaftPos_Rstation5))
                                //{
                                Step2 = Step2 + 1;
                                //}
                            }
                            break;

                        case 54: //摆臂到取料位置
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RlaserInitialPos_Rstation7.X4AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X4初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RccdInitialPos_Rstation6.Z11AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ14初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在负限位安全位置，请检查");
                                break;
                            }

                            //抬升安全Z
                            Rpp = Machine.pos_RrockInitialPos_Rstation5.Clone();
                            Rpp.isShowY4Position = false;
                            Rpp.isShowZ12Position = true;
                            Rpp.AxisPriority = "1";
                            if (MotionControl.AxesMove(Rpp) == true)
                            {
                                //走Y
                                Rpp = Machine.pos_Rrock2FetchPos_Rstation5.Clone();
                                Rpp.isShowY4Position = true;
                                Rpp.isShowZ12Position = false;
                                Rpp.AxisPriority = "1";
                                if (MotionControl.AxesMove(Rpp) == true)
                                {
                                    //走Z
                                    Rpp = Machine.pos_Rrock2FetchPos_Rstation5.Clone();
                                    Rpp.isShowY4Position = false;
                                    Rpp.isShowZ12Position = true;
                                    Rpp.AxisPriority = "1";
                                    if (MotionControl.AxesMove(Rpp) == true)
                                    {
                                        Machine.do_量测右定位机构载盘吸嘴吸.ON();
                                        Thread.Sleep(500);
                                        Machine.do_量测右搬运工位前吸嘴吸.OFF();
                                        Machine.do_量测右搬运工位中吸嘴吸.OFF();
                                        Machine.do_量测右搬运工位后吸嘴吸.OFF();
                                        Thread.Sleep(200);
                                        Step2 = Step2 + 1;
                                    }
                                }
                            }
                            break;

                        case 55: //摆臂Z轴提升到安全位置
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RlaserInitialPos_Rstation7.X4AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X4初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RccdInitialPos_Rstation6.Z11AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ14初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在负限位安全位置，请检查");
                                break;
                            }
                            Rpp = Machine.pos_RrockInitialPos_Rstation5.Clone();
                            Rpp.isShowY4Position = false;
                            Rpp.isShowZ12Position = true;
                            Rpp.AxisPriority = "1";
                            if (MotionControl.AxesMove(Rpp) == true)
                            {
                                Rpp = Machine.pos_RrockInitialPos_Rstation5.Clone();
                                Rpp.isShowY4Position = true;
                                Rpp.isShowZ12Position = false;
                                Rpp.AxisPriority = "1";
                                if (MotionControl.AxesMove(Rpp) == true)
                                {
                                    Step2 = Step2 + 1;
                                }
                            }
                            break;
                        #endregion

                        case 56: //摆臂返回OK    判断循环次数
                            RgrrCount++;
                            if (RgrrCount == Common.RightGrrCount)
                            {
                                RgrrCount = 0;
                                Machine.do_量测右定位机构载盘吸嘴吸.OFF();
                                Machine.do_量测右定位机构定位气缸伸出.ON();
                                Machine.do_量测右定位机构定位气缸缩回.OFF();
                                MessageBox.Show("右Grr完成，请取出料");
                                RightGrrIng = false;
                                Step2 = 1;
                                return;
                            }
                            else
                            {
                                Step2 = 2;
                            }
                            break;
                    }
                }
            }
        }

        int Step3 = 1;//左清料
        int Step4 = 1;//右清料
        public bool LeftClearFinish = false;
        public bool RightClearFinish = false;
        HObject RaserImage = new HObject();

        private void LeftClera()
        {
            while (true)
            {
                if (LeftClearFinish == true)
                {
                    LeftClearFinish = false;
                    break;
                }
                Thread.Sleep(10);
                if (MachineStatusManager.CurrentMachineStatus == MachineStatus.Running)
                {
                    switch (Step3)
                    {
                        case 1:
                            //判定是否满足清料条件
                            if (Left_MeasurementLocation.isAllowClear == true && Left_MeasurementRotate.isAllowClear == true
                                && LeftSwingArm_MeasurementStation.isAllowClear == true)//
                            {
                                Left_MeasurementLocation.isAllowClear = false;
                                Left_MeasurementRotate.isAllowClear = false;
                                LeftSwingArm_MeasurementStation.isAllowClear = false;
                                Common.LeftClearing = true;

                                if (Left_MeasurementUpCCD.count == 1)//清一颗料
                                {
                                    Left_MeasurementUpCCD.count = 0;
                                    Step3 = 100;
                                }
                                else//清2颗以上的料
                                {
                                    Left_MeasurementUpCCD.count = 0;
                                    Step3 = Step3 + 1;
                                }
                            }
                            else
                            {
                                MessageBox.Show("english:Left state CanNot Clear!--chinese:设备左穴状态不满足清料!");
                                return;
                            }
                            break;

                        case 2: //摆臂到取料位置   打开摆臂中后吸气     关闭量测真空
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LlaserInitialPos_Lstation7.X2AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X3初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LccdInitialPos_Lstation6.Z5AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ15初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在正限位安全位置，请检查");
                                break;
                            }

                            pp = Machine.pos_LrockInitialPos_Lstation5.Clone();
                            pp.isShowY2Position = false;
                            pp.isShowZ6Position = true;
                            pp.AxisPriority = "1";
                            if (MotionControl.AxesMove(pp) == true)
                            {
                                //走Y
                                pp = Machine.pos_Lrock2FetchPos_Lstation5.Clone();
                                pp.isShowY2Position = true;
                                pp.isShowZ6Position = false;
                                pp.AxisPriority = "1";
                                if (MotionControl.AxesMove(pp) == true)
                                {
                                    //走Z
                                    pp = Machine.pos_Lrock2FetchPos_Lstation5.Clone();
                                    pp.isShowY2Position = false;
                                    pp.isShowZ6Position = true;
                                    pp.AxisPriority = "1";
                                    if (MotionControl.AxesMove(pp))
                                    {
                                        Machine.do_量测左搬运工位中吸嘴吸.ON();
                                        Machine.do_量测左搬运工位后吸嘴吸.ON();
                                        Thread.Sleep(500);

                                        Machine.do_量测左定位机构载盘吸嘴吸.OFF();
                                        Machine.do_量测左上CCD载盘吸嘴吸.OFF();
                                        Machine.do_量测左上激光载盘吸嘴吸.OFF();
                                        Machine.do_量测左CCD旋转工位吸嘴吸.OFF();
                                        Thread.Sleep(200);
                                        Step3 = Step3 + 1;
                                    }
                                }
                            }
                            break;

                        case 3: //摆臂Z轴提升到安全位置
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LlaserInitialPos_Lstation7.X2AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X3初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LccdInitialPos_Lstation6.Z5AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ15初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在正限位安全位置，请检查");
                                break;
                            }
                            pp = Machine.pos_LrockInitialPos_Lstation5.Clone();
                            pp.isShowY2Position = false;
                            pp.isShowZ6Position = true;
                            pp.AxisPriority = "1";
                            if (MotionControl.AxesMove(pp) == true)
                            {
                                Step3 = Step3 + 1;
                            }
                            break;

                        #region 下CCD拍照处理
                        case 4:  //如果需要下CCD拍照则移动到下CCD 拍照位置  
                            if (MotionControl.AxesMove(Machine.pos_Lrock2BottomCCDPos_Lstation5))
                            {
                                Step3 = Step3 + 1;
                            }
                            break;

                        case 5:
                            string strLeftStation3 = string.Empty;
                            Common.light3.WriteData(Common.lightList[(int)LIGHT_ENUM.左工位3下同轴光SN].Chanel, Common.lightList[(int)LIGHT_ENUM.左工位3下同轴光SN].Value);
                            Thread.Sleep(50);
                            //发送第一次拍照
                            Machine.SecondComputerSocket.SendStr("Station3_1" + Environment.NewLine);
                            while (Common.strStation3_1 == string.Empty)
                            {
                                Thread.Sleep(10);
                            }
                            Common.strStation3_1 = string.Empty;
                            Common.light3.WriteData(Common.lightList[(int)LIGHT_ENUM.左工位3下同轴光SN].Chanel, 0);

                            ///第2次拍照
                            Common.light3.WriteData(Common.lightList[(int)LIGHT_ENUM.左工位3下同轴光].Chanel, Common.lightList[(int)LIGHT_ENUM.左工位3下同轴光].Value);
                            Thread.Sleep(50);
                            Machine.SecondComputerSocket.SendStr("Station3_2" + Environment.NewLine);
                            while (Common.strStation3_2 == string.Empty)
                            {
                                Thread.Sleep(10);
                            }
                            Common.strStation3_2 = string.Empty;
                            Common.light3.WriteData(Common.lightList[(int)LIGHT_ENUM.左工位3下同轴光].Chanel, 0);

                            ///第3次拍照
                            Common.light3.WriteData(Common.lightList[(int)LIGHT_ENUM.左工位3下同轴光2].Chanel, Common.lightList[(int)LIGHT_ENUM.左工位3下同轴光2].Value);
                            Thread.Sleep(50);
                            Machine.SecondComputerSocket.SendStr("Station3_3" + Environment.NewLine);
                            while (Common.strStation3_3 == string.Empty)
                            {
                                Thread.Sleep(10);
                            }
                            Common.strStation3_3 = string.Empty;
                            Common.light3.WriteData(Common.lightList[(int)LIGHT_ENUM.左工位3下同轴光2].Chanel, 0);

                            ///////接受量测值
                            Machine.SecondComputerSocket.SendStr("Station3_Calculation" + Environment.NewLine);

                            //接受量测值
                            while (Common.strStation3 == string.Empty)
                            {
                                Thread.Sleep(10);
                            }
                            string strRightStation3 = string.Empty;
                            strRightStation3 = Common.strStation3;
                            Common.strStation3 = string.Empty;
                            Common.AppendUiLog.Log(strRightStation3, LogType.Alert);

                            //数据融合
                            string[] revData1 = strRightStation3.Split(',');
                            MeasureProduct mp = new MeasureProduct();
                            Common.Station2Queue_L.TryDequeue(out mp);
                            for (int i = 0; i < revData1.Length; i++)
                            {
                                if (revData1[i].Contains(":"))
                                {
                                    string FAIName = revData1[i].Split(':')[0];
                                    string FAIValue = revData1[i].Split(':')[1];
                                    DataItem FAI = new DataItem();
                                    FAI.Name = FAIName;
                                    if (FAIName != "SN")
                                    {
                                        FAI.Value = double.Parse(FAIValue);
                                        FAI.Position = 0;
                                        mp.MeasureData.Add(FAI);
                                    }
                                    else
                                    {
                                        mp.SN = FAIValue;
                                    }
                                }
                            }
                            //数据入队
                            Common.Station3Queue_L.Enqueue(mp);
                            Step3 = Step3 + 1;
                            break;
                        #endregion

                        case 6: //摆臂到放料位置   关闭摆臂真空   打开量测真空吸
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LlaserInitialPos_Lstation7.X2AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X3初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LccdInitialPos_Lstation6.Z5AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ15初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在正限位安全位置，请检查");
                                break;
                            }
                            //TODO X轴移动到放料位
                            pp = Machine.pos_Lrock2PutPos_Lstation5.Clone();
                            pp.isShowY2Position = true;
                            pp.isShowZ6Position = false;
                            pp.AxisPriority = "1";
                            if (MotionControl.AxesMove(pp) == true)
                            {
                                pp = Machine.pos_Lrock2PutPos_Lstation5.Clone();
                                pp.isShowY2Position = false;
                                pp.isShowZ6Position = true;
                                pp.AxisPriority = "1";
                                if (MotionControl.AxesMove(pp) == true)
                                {
                                    Machine.do_量测左上激光载盘吸嘴吸.ON();       ////激光
                                    Machine.do_量测左CCD旋转工位吸嘴吸.ON();
                                    Thread.Sleep(500);

                                    Machine.do_量测左搬运工位前吸嘴吸.OFF();
                                    Machine.do_量测左搬运工位中吸嘴吸.OFF();
                                    Machine.do_量测左搬运工位后吸嘴吸.OFF();
                                    Thread.Sleep(200);
                                    Step3 = Step3 + 1;
                                }
                            }
                            break;

                        case 7: //摆臂到安全位置   
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LlaserInitialPos_Lstation7.X2AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X3初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LccdInitialPos_Lstation6.Z5AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ15初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在正限位安全位置，请检查");
                                break;
                            }
                            pp = Machine.pos_LrockSaftPos_Lstation5.Clone();
                            pp.isShowY2Position = false;
                            pp.isShowZ6Position = true;
                            pp.AxisPriority = "1";
                            if (MotionControl.AxesMove(pp) == true)
                            {
                                if (MotionControl.AxesMove(Machine.pos_LrockSaftPos_Lstation5))
                                {
                                    Step3 = Step3 + 1;
                                }
                            }
                            break;

                        #region 激光处理
                        case 8:  //移动到激光测试的初始位置
                            if (MotionControl.AxesMove(Machine.pos_LlaserStartPos_Lstation7))
                            {
                                Step3 = Step3 + 1;
                            }
                            break;

                        case 9:   //打开激光触发
                            Machine.SecondComputerSocket.SendStr("LaserStart" + Environment.NewLine);
                            while (Common.strStation4LaserStart != "LaserStart")
                            {
                                Thread.Sleep(10);
                            }
                            Machine.do_左工位点激光触发.ON();
                            Common.strStation4LaserStart = string.Empty;
                            Step3 = Step3 + 1;
                            break;

                        case 10:   //运动到激光测量终点位置
                            if (MotionControl.AxesMove(Machine.pos_LlaserEndPos_Lstation7))
                            {
                                Machine.do_左工位点激光触发.OFF();
                                Step3 = Step3 + 1;
                            }
                            break;

                        case 11: //采图并关闭激光触发
                            Machine.SecondComputerSocket.SendStr("LaserStop" + Environment.NewLine);
                            Step3 = Step3 + 1;
                            break;

                        case 12:    //激光处理
                            if (MotionControl.AxesMove(Machine.pos_LlaserInitialPos_Lstation7))//运动到安全位   
                            {

                                while (Common.strStation4 == string.Empty)
                                {
                                    Thread.Sleep(10);
                                }
                                string strLeftStation4 = string.Empty;
                                strLeftStation4 = Common.strStation4;
                                Common.strStation4 = string.Empty;


                                //数据拆分
                                Common.AppendUiLog.Log(strLeftStation4, LogType.Alert);
                                string[] revData14 = strLeftStation4.Split(',');
                                //数据融合
                                MeasureProduct mp4 = new MeasureProduct();
                                Common.Station3Queue_L.TryDequeue(out mp4);
                                for (int i = 0; i < revData14.Length; i++)
                                {
                                    if (revData14[i].Contains(":"))
                                    {
                                        string FAIName = revData14[i].Split(':')[0];
                                        string FAIValue = revData14[i].Split(':')[1];
                                        DataItem FAI = new DataItem();
                                        FAI.Name = FAIName;
                                        FAI.Value = double.Parse(FAIValue);
                                        FAI.Position = 0;
                                        mp4.MeasureData.Add(FAI);
                                    }
                                }
                                //数据入队
                                Common.Station4Queue_L.Enqueue(mp4);
                                Step3 = Step3 + 1;
                            }
                            break;

                        case 13: //等待激光处理结果并轴回到初始位
                            if (MotionControl.CheckMoveDone(Machine.pos_LlaserInitialPos_Lstation7))
                            {
                                Step3 = Step3 + 1;
                            }
                            break;
                        #endregion

                        #region 旋转工位拍照计算   下料机械手取料完成
                        case 14:
                            //TODO 旋转45°
                            if (MotionControl.AxesMove(Machine.pos_Lrotate1Pos_Lstation8) == true)
                            {
                                Step3 = Step3 + 1;
                            }
                            break;

                        case 15:  //第一次拍照
                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.左工位5侧背光].Chanel, Common.lightList[(int)LIGHT_ENUM.左工位5侧背光].Value);
                            //第一次拍照指令
                            Machine.SecondComputerSocket.SendStr("Station5,1" + Environment.NewLine);
                            while (Common.strStation5_1 != "Station5,1")
                            {
                                Thread.Sleep(10);
                            }
                            Common.strStation5_1 = "";
                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.左工位5侧背光].Chanel, 0);
                            Step3 = Step3 + 1;
                            break;

                        case 16:  //调用计算的视觉算子
                            Machine.SecondComputerSocket.SendStr("Station5_1_Calculation" + Environment.NewLine);
                            while (Common.strStation5_Cam1OK != "Cam1OK")
                            {
                                Thread.Sleep(10);
                            }
                            Common.strStation5_Cam1OK = "";
                            Step3 = Step3 + 1;
                            break;

                        case 17:
                            //TODO 旋转45°
                            if (MotionControl.AxesMove(Machine.pos_Lrotate2Pos_Lstation8) == true)
                            {
                                Step3 = Step3 + 1;
                            }
                            break;

                        case 18: //第二次拍照
                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.左工位5侧背光].Chanel, Common.lightList[(int)LIGHT_ENUM.左工位5侧背光].Value);
                            Thread.Sleep(50);
                            Machine.SecondComputerSocket.SendStr("Station5,2" + Environment.NewLine);
                            while (Common.strStation5_2 != "Station5,2")
                            {
                                Thread.Sleep(10);
                            }
                            Common.strStation5_2 = "";
                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.左工位5侧背光].Chanel, 0);
                            Step3 = Step3 + 1;
                            break;

                        case 19:
                            Machine.SecondComputerSocket.SendStr("Station5_2_Calculation" + Environment.NewLine);
                            while (Common.strStation5_Cam2OK != "Cam2OK")
                            {
                                Thread.Sleep(10);
                            }
                            Common.strStation5_Cam2OK = "";
                            Step3 = Step3 + 1;
                            break;

                        case 20:
                            //TODO 旋转45°
                            if (MotionControl.AxesMove(Machine.pos_Lrotate3Pos_Lstation8) == true)
                            {
                                Step3 = Step3 + 1;
                            }
                            break;

                        case 21:  //第三次拍照
                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.左工位5侧背光].Chanel, Common.lightList[(int)LIGHT_ENUM.左工位5侧背光].Value);
                            Thread.Sleep(50);
                            Machine.SecondComputerSocket.SendStr("Station5,3" + Environment.NewLine);
                            while (Common.strStation5_3 != "Station5,3")
                            {
                                Thread.Sleep(10);
                            }
                            Common.strStation5_3 = "";
                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.左工位5侧背光].Chanel, 0);
                            Step3 = Step3 + 1;
                            break;

                        case 22:
                            Machine.SecondComputerSocket.SendStr("Station5_3_Calculation" + Environment.NewLine);
                            while (Common.strStation5_Cam3OK != "Cam3OK")
                            {
                                Thread.Sleep(10);
                            }
                            Common.strStation5_Cam3OK = "";
                            Step3 = Step3 + 1;
                            break;

                        case 23:
                            //TODO 旋转45°
                            if (MotionControl.AxesMove(Machine.pos_Lrotate4Pos_Lstation8) == true)
                            {
                                Step3 = Step3 + 1;
                            }
                            break;

                        case 24:// 第4次拍照
                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.左工位5侧背光].Chanel, Common.lightList[(int)LIGHT_ENUM.左工位5侧背光].Value);
                            Thread.Sleep(50);
                            Machine.SecondComputerSocket.SendStr("Station5,4" + Environment.NewLine);
                            while (Common.strStation5_4 != "Station5,4")
                            {
                                Thread.Sleep(10);
                            }
                            Common.strStation5_4 = "";
                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.左工位5侧背光].Chanel, 0);
                            Step3 = Step3 + 1;
                            break;

                        case 25:
                            Machine.SecondComputerSocket.SendStr("Station5_4_Calculation" + Environment.NewLine);
                            while (Common.strStation5_Cam4OK != "Cam4OK")
                            {
                                Thread.Sleep(10);
                            }
                            Common.strStation5_Cam4OK = "";
                            Step3 = Step3 + 1;
                            break;

                        case 26:    //旋转轴转到初始位置
                            MotionControl.AxesMoveNoWait(Machine.pos_LrotateInitialPos_Lstation8);//异步运动到安全位
                            Step3 = Step3 + 1;
                            break;

                        case 27:
                            Machine.SecondComputerSocket.SendStr("Station5_Calculation" + Environment.NewLine);
                            while (Common.strStation5 == string.Empty)
                            {
                                Thread.Sleep(10);
                            }
                            string strLeftStation5 = string.Empty;

                            strLeftStation5 = Common.strStation5;
                            Common.strStation5 = string.Empty;
                            Common.AppendUiLog.Log(strLeftStation5, LogType.Alert);

                            //数据融合
                            string[] revData15 = strLeftStation5.Split(',');
                            MeasureProduct mp5 = new MeasureProduct();
                            Common.Station4Queue_L.TryDequeue(out mp5);

                            mp5.Position = "0";
                            for (int i = 0; i < revData15.Length; i++)
                            {
                                if (revData15[i].Contains(":"))
                                {
                                    string FAIName = revData15[i].Split(':')[0];
                                    string FAIValue = revData15[i].Split(':')[1];
                                    DataItem FAI = new DataItem();
                                    FAI.Name = FAIName;
                                    FAI.Value = double.Parse(FAIValue);
                                    FAI.Position = 0;
                                    mp5.MeasureData.Add(FAI);
                                }
                            }
                            //数据入队
                            Common.Station5Queue_L.Enqueue(mp5);
                            Step3 = Step3 + 1;
                            break;

                        case 28:      //整合产品的数据
                            MeasureProduct mp1 = new MeasureProduct();
                            Common.Station5Queue_L.TryDequeue(out mp1);
                            JUDGEMENT_RESULT ret = ProcessData.PrcessData(mp1);
                            string result = "";
                            if (ret == JUDGEMENT_RESULT.OK)
                            {
                                result = "OK";
                            }
                            else
                            {
                                result = "NG";
                            }
                            if (ret == JUDGEMENT_RESULT.OK)
                            {
                                Machine.SecondComputerSocket.SendStr("ResultOK" + Environment.NewLine);
                            }
                            else
                            {
                                Machine.SecondComputerSocket.SendStr("ResultNG" + Environment.NewLine);
                            }

                            LMergedDataFininshed = true;
                            Step3 = Step3 + 1;
                            break;

                        case 29:   //等待旋转轴转到初始位置
                            if (MotionControl.CheckMoveDone(Machine.pos_LrotateInitialPos_Lstation8))
                            {
                                Step3 = Step3 + 1;
                            }

                            break;

                        case 30:    //发送允许下料机械手取料的信号
                            if (Common.resultLeft == true && Common.isResultLeftRefresh == true)
                            {
                                Common.isResultLeftRefresh = false;
                                Common.resultLeft = null;
                                Machine.do_给下工位左产品OK信号.ON();
                            }
                            else if (Common.resultLeft == false && Common.isResultLeftRefresh == true)
                            {
                                Common.isResultLeftRefresh = false;
                                Common.resultLeft = null;
                                Machine.do_给下工位左产品NG信号.ON();
                            }
                            Step3 = Step3 + 1;
                            break;

                        case 31:     // //等待下料机械手到位,给破真空完成信号
                            if (Machine.di_下料机左机械手到位信号.GetStatus() == true)
                            {
                                Machine.do_量测左CCD旋转工位吸嘴吸.OFF();
                                Thread.Sleep(100);
                                Machine.do_给下料机左破真空完成.ON();
                                Step3 = Step3 + 1;
                            }
                            break;

                        case 32:     //等待下料机械手取料完成信号
                            if (Machine.di_下料左取料完成.GetStatus() == true || Common.DownLeftRobotTakFinish == true)
                            {
                                Machine.do_给下料机左破真空完成.OFF();
                                Machine.do_给下工位左产品OK信号.OFF();
                                Machine.do_给下工位左产品NG信号.OFF();
                                Step3 = Step3 + 1;
                            }
                            break;
                        #endregion

                        case 33: //摆臂到取料位置   打开摆臂右吸气     关闭量测真空
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LlaserInitialPos_Lstation7.X2AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X3初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LccdInitialPos_Lstation6.Z5AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ15初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在正限位安全位置，请检查");
                                break;
                            }

                            pp = Machine.pos_LrockInitialPos_Lstation5.Clone();
                            pp.isShowY2Position = false;
                            pp.isShowZ6Position = true;
                            pp.AxisPriority = "1";
                            if (MotionControl.AxesMove(pp) == true)
                            {
                                //走Y
                                pp = Machine.pos_Lrock2FetchPos_Lstation5.Clone();
                                pp.isShowY2Position = true;
                                pp.isShowZ6Position = false;
                                pp.AxisPriority = "1";
                                if (MotionControl.AxesMove(pp) == true)
                                {
                                    //走Z
                                    pp = Machine.pos_Lrock2FetchPos_Lstation5.Clone();
                                    pp.isShowY2Position = false;
                                    pp.isShowZ6Position = true;
                                    pp.AxisPriority = "1";
                                    if (MotionControl.AxesMove(pp))
                                    {
                                        Machine.do_量测左搬运工位后吸嘴吸.ON();
                                        Thread.Sleep(500);

                                        Machine.do_量测左定位机构载盘吸嘴吸.OFF();
                                        Machine.do_量测左上CCD载盘吸嘴吸.OFF();
                                        Machine.do_量测左上激光载盘吸嘴吸.OFF();
                                        Machine.do_量测左CCD旋转工位吸嘴吸.OFF();
                                        Thread.Sleep(200);
                                        Step3 = Step3 + 1;
                                    }
                                }
                            }
                            break;

                        case 34: //摆臂Z轴提升到安全位置
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LlaserInitialPos_Lstation7.X2AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X3初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LccdInitialPos_Lstation6.Z5AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ15初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在正限位安全位置，请检查");
                                break;
                            }
                            pp = Machine.pos_LrockInitialPos_Lstation5.Clone();
                            pp.isShowY2Position = false;
                            pp.isShowZ6Position = true;
                            pp.AxisPriority = "1";
                            if (MotionControl.AxesMove(pp) == true)
                            {
                                Step3 = Step3 + 1;
                            }
                            break;

                        case 35: //摆臂到放料位置   关闭摆臂真空   打开量测真空吸
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LlaserInitialPos_Lstation7.X2AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X3初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LccdInitialPos_Lstation6.Z5AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ15初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在正限位安全位置，请检查");
                                break;
                            }
                            //TODO X轴移动到放料位
                            pp = Machine.pos_Lrock2PutPos_Lstation5.Clone();
                            pp.isShowY2Position = true;
                            pp.isShowZ6Position = false;
                            pp.AxisPriority = "1";
                            if (MotionControl.AxesMove(pp) == true)
                            {
                                pp = Machine.pos_Lrock2PutPos_Lstation5.Clone();
                                pp.isShowY2Position = false;
                                pp.isShowZ6Position = true;
                                pp.AxisPriority = "1";
                                if (MotionControl.AxesMove(pp) == true)
                                {
                                    Machine.do_量测左CCD旋转工位吸嘴吸.ON();
                                    Thread.Sleep(500);

                                    Machine.do_量测左搬运工位前吸嘴吸.OFF();
                                    Machine.do_量测左搬运工位中吸嘴吸.OFF();
                                    Machine.do_量测左搬运工位后吸嘴吸.OFF();
                                    Thread.Sleep(200);
                                    Step3 = Step3 + 1;
                                }
                            }
                            break;

                        case 36: //摆臂到安全位置   
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LlaserInitialPos_Lstation7.X2AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X3初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LccdInitialPos_Lstation6.Z5AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ15初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在正限位安全位置，请检查");
                                break;
                            }
                            pp = Machine.pos_LrockSaftPos_Lstation5.Clone();
                            pp.isShowY2Position = false;
                            pp.isShowZ6Position = true;
                            pp.AxisPriority = "1";
                            if (MotionControl.AxesMove(pp) == true)
                            {
                                if (MotionControl.AxesMove(Machine.pos_LrockSaftPos_Lstation5))
                                {
                                    Step3 = Step3 + 1;
                                }
                            }
                            break;

                        #region 旋转工位拍照计算   下料机械手取料完成
                        case 37:
                            //TODO 旋转45°
                            if (MotionControl.AxesMove(Machine.pos_Lrotate1Pos_Lstation8) == true)
                            {
                                Step3 = Step3 + 1;
                            }
                            break;

                        case 38:  //第一次拍照
                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.左工位5侧背光].Chanel, Common.lightList[(int)LIGHT_ENUM.左工位5侧背光].Value);
                            //第一次拍照指令
                            Machine.SecondComputerSocket.SendStr("Station5,1" + Environment.NewLine);
                            while (Common.strStation5_1 != "Station5,1")
                            {
                                Thread.Sleep(10);
                            }
                            Common.strStation5_1 = "";
                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.左工位5侧背光].Chanel, 0);
                            Step3 = Step3 + 1;
                            break;

                        case 39:  //调用计算的视觉算子
                            Machine.SecondComputerSocket.SendStr("Station5_1_Calculation" + Environment.NewLine);
                            while (Common.strStation5_Cam1OK != "Cam1OK")
                            {
                                Thread.Sleep(10);
                            }
                            Common.strStation5_Cam1OK = "";
                            Step3 = Step3 + 1;
                            break;

                        case 40:
                            //TODO 旋转45°
                            if (MotionControl.AxesMove(Machine.pos_Lrotate2Pos_Lstation8) == true)
                            {
                                Step3 = Step3 + 1;
                            }
                            break;

                        case 41: //第二次拍照
                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.左工位5侧背光].Chanel, Common.lightList[(int)LIGHT_ENUM.左工位5侧背光].Value);
                            Thread.Sleep(50);
                            Machine.SecondComputerSocket.SendStr("Station5,2" + Environment.NewLine);
                            while (Common.strStation5_2 != "Station5,2")
                            {
                                Thread.Sleep(10);
                            }
                            Common.strStation5_2 = "";
                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.左工位5侧背光].Chanel, 0);
                            Step3 = Step3 + 1;
                            break;

                        case 42:
                            Machine.SecondComputerSocket.SendStr("Station5_2_Calculation" + Environment.NewLine);
                            while (Common.strStation5_Cam2OK != "Cam2OK")
                            {
                                Thread.Sleep(10);
                            }
                            Common.strStation5_Cam2OK = "";
                            Step3 = Step3 + 1;
                            break;

                        case 43:
                            //TODO 旋转45°
                            if (MotionControl.AxesMove(Machine.pos_Lrotate3Pos_Lstation8) == true)
                            {
                                Step3 = Step3 + 1;
                            }
                            break;

                        case 44:  //第三次拍照
                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.左工位5侧背光].Chanel, Common.lightList[(int)LIGHT_ENUM.左工位5侧背光].Value);
                            Thread.Sleep(50);
                            Machine.SecondComputerSocket.SendStr("Station5,3" + Environment.NewLine);
                            while (Common.strStation5_3 != "Station5,3")
                            {
                                Thread.Sleep(10);
                            }
                            Common.strStation5_3 = "";
                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.左工位5侧背光].Chanel, 0);
                            Step3 = Step3 + 1;
                            break;

                        case 45:
                            Machine.SecondComputerSocket.SendStr("Station5_3_Calculation" + Environment.NewLine);
                            while (Common.strStation5_Cam3OK != "Cam3OK")
                            {
                                Thread.Sleep(10);
                            }
                            Common.strStation5_Cam3OK = "";
                            Step3 = Step3 + 1;
                            break;

                        case 46:
                            //TODO 旋转45°
                            if (MotionControl.AxesMove(Machine.pos_Lrotate4Pos_Lstation8) == true)
                            {
                                Step3 = Step3 + 1;
                            }
                            break;

                        case 47:// 第4次拍照
                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.左工位5侧背光].Chanel, Common.lightList[(int)LIGHT_ENUM.左工位5侧背光].Value);
                            Thread.Sleep(50);
                            Machine.SecondComputerSocket.SendStr("Station5,4" + Environment.NewLine);
                            while (Common.strStation5_4 != "Station5,4")
                            {
                                Thread.Sleep(10);
                            }
                            Common.strStation5_4 = "";
                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.左工位5侧背光].Chanel, 0);
                            Step3 = Step3 + 1;
                            break;

                        case 48:
                            Machine.SecondComputerSocket.SendStr("Station5_4_Calculation" + Environment.NewLine);
                            while (Common.strStation5_Cam4OK != "Cam4OK")
                            {
                                Thread.Sleep(10);
                            }
                            Common.strStation5_Cam4OK = "";
                            Step3 = Step3 + 1;
                            break;

                        case 49:    //旋转轴转到初始位置
                            MotionControl.AxesMoveNoWait(Machine.pos_LrotateInitialPos_Lstation8);//异步运动到安全位
                            Step3 = Step3 + 1;
                            break;

                        case 50:
                            Machine.SecondComputerSocket.SendStr("Station5_Calculation" + Environment.NewLine);
                            while (Common.strStation5 == string.Empty)
                            {
                                Thread.Sleep(10);
                            }
                            //string strLeftStation5_1 = string.Empty;

                            strLeftStation5 = Common.strStation5;
                            Common.strStation5 = string.Empty;
                            Common.AppendUiLog.Log(strLeftStation5, LogType.Alert);

                            //数据融合
                            string[] revData15_1 = strLeftStation5.Split(',');
                            MeasureProduct mp5_1 = new MeasureProduct();
                            Common.Station4Queue_L.TryDequeue(out mp5_1);

                            mp5_1.Position = "0";
                            for (int i = 0; i < revData15_1.Length; i++)
                            {
                                if (revData15_1[i].Contains(":"))
                                {
                                    string FAIName = revData15_1[i].Split(':')[0];
                                    string FAIValue = revData15_1[i].Split(':')[1];
                                    DataItem FAI = new DataItem();
                                    FAI.Name = FAIName;
                                    FAI.Value = double.Parse(FAIValue);
                                    FAI.Position = 0;
                                    mp5_1.MeasureData.Add(FAI);
                                }
                            }
                            //数据入队
                            Common.Station5Queue_L.Enqueue(mp5_1);
                            Step3 = Step3 + 1;
                            break;

                        case 51:      //整合产品的数据
                            MeasureProduct mp1_1 = new MeasureProduct();
                            Common.Station5Queue_L.TryDequeue(out mp1_1);
                            JUDGEMENT_RESULT ret1 = ProcessData.PrcessData(mp1_1);
                            string result1 = "";
                            if (ret1 == JUDGEMENT_RESULT.OK)
                            {
                                result1 = "OK";
                            }
                            else
                            {
                                result1 = "NG";
                            }
                            if (ret1 == JUDGEMENT_RESULT.OK)
                            {
                                Machine.SecondComputerSocket.SendStr("ResultOK" + Environment.NewLine);
                            }
                            else
                            {
                                Machine.SecondComputerSocket.SendStr("ResultNG" + Environment.NewLine);
                            }

                            LMergedDataFininshed = true;
                            Step3 = Step3 + 1;
                            break;

                        case 52:   //等待旋转轴转到初始位置
                            if (MotionControl.CheckMoveDone(Machine.pos_LrotateInitialPos_Lstation8))
                            {
                                Step3 = Step3 + 1;
                            }

                            break;

                        case 53:    //发送允许下料机械手取料的信号
                            if (Common.resultLeft == true && Common.isResultLeftRefresh == true)
                            {
                                Common.isResultLeftRefresh = false;
                                Common.resultLeft = null;
                                Machine.do_给下工位左产品OK信号.ON();
                            }
                            else if (Common.resultLeft == false && Common.isResultLeftRefresh == true)
                            {
                                Common.isResultLeftRefresh = false;
                                Common.resultLeft = null;
                                Machine.do_给下工位左产品NG信号.ON();
                            }
                            Step3 = Step3 + 1;
                            break;

                        case 54:     // //等待下料机械手到位,给破真空完成信号
                            if (Machine.di_下料机左机械手到位信号.GetStatus() == true)
                            {
                                Machine.do_量测左CCD旋转工位吸嘴吸.OFF();
                                Thread.Sleep(100);
                                Machine.do_给下料机左破真空完成.ON();
                                Step3 = Step3 + 1;
                            }
                            break;

                        case 55:     //等待下料机械手取料完成信号
                            if (Machine.di_下料左取料完成.GetStatus() == true || Common.DownLeftRobotTakFinish == true)
                            {
                                Machine.do_给下料机左破真空完成.OFF();
                                Machine.do_给下工位左产品OK信号.OFF();
                                Machine.do_给下工位左产品NG信号.OFF();
                                Step3 = 56;
                            }
                            break;
                        #endregion

                        #region 清1颗料的情况

                        case 100: //摆臂到取料位置   打开摆臂中后吸气     关闭量测真空
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LlaserInitialPos_Lstation7.X2AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X3初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LccdInitialPos_Lstation6.Z5AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ15初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在正限位安全位置，请检查");
                                break;
                            }

                            pp = Machine.pos_LrockInitialPos_Lstation5.Clone();
                            pp.isShowY2Position = false;
                            pp.isShowZ6Position = true;
                            pp.AxisPriority = "1";
                            if (MotionControl.AxesMove(pp) == true)
                            {
                                //走Y
                                pp = Machine.pos_Lrock2FetchPos_Lstation5.Clone();
                                pp.isShowY2Position = true;
                                pp.isShowZ6Position = false;
                                pp.AxisPriority = "1";
                                if (MotionControl.AxesMove(pp) == true)
                                {
                                    //走Z
                                    pp = Machine.pos_Lrock2FetchPos_Lstation5.Clone();
                                    pp.isShowY2Position = false;
                                    pp.isShowZ6Position = true;
                                    pp.AxisPriority = "1";
                                    if (MotionControl.AxesMove(pp))
                                    {
                                        Machine.do_量测左搬运工位中吸嘴吸.ON();
                                        //Machine.do_量测左搬运工位后吸嘴吸.ON();
                                        Thread.Sleep(500);

                                        Machine.do_量测左定位机构载盘吸嘴吸.OFF();
                                        Machine.do_量测左上CCD载盘吸嘴吸.OFF();
                                        Machine.do_量测左上激光载盘吸嘴吸.OFF();
                                        Machine.do_量测左CCD旋转工位吸嘴吸.OFF();
                                        Thread.Sleep(200);
                                        Step3 = Step3 + 1;
                                    }
                                }
                            }
                            break;

                        case 101: //摆臂Z轴提升到安全位置
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LlaserInitialPos_Lstation7.X2AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X3初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LccdInitialPos_Lstation6.Z5AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ15初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在正限位安全位置，请检查");
                                break;
                            }
                            pp = Machine.pos_LrockInitialPos_Lstation5.Clone();
                            pp.isShowY2Position = false;
                            pp.isShowZ6Position = true;
                            pp.AxisPriority = "1";
                            if (MotionControl.AxesMove(pp) == true)
                            {
                                Step3 = Step3 + 1;
                            }
                            break;

                        #region 下CCD拍照处理
                        case 102:  //如果需要下CCD拍照则移动到下CCD 拍照位置  
                            if (MotionControl.AxesMove(Machine.pos_Lrock2BottomCCDPos_Lstation5))
                            {
                                Step3 = Step3 + 1;
                            }
                            break;

                        case 103:
                            //string strLeftStation3 = string.Empty;
                            Common.light3.WriteData(Common.lightList[(int)LIGHT_ENUM.左工位3下同轴光SN].Chanel, Common.lightList[(int)LIGHT_ENUM.左工位3下同轴光SN].Value);
                            Thread.Sleep(50);
                            //发送第一次拍照
                            Machine.SecondComputerSocket.SendStr("Station3_1" + Environment.NewLine);
                            while (Common.strStation3_1 == string.Empty)
                            {
                                Thread.Sleep(10);
                            }
                            Common.strStation3_1 = string.Empty;
                            Common.light3.WriteData(Common.lightList[(int)LIGHT_ENUM.左工位3下同轴光SN].Chanel, 0);

                            ///第2次拍照
                            Common.light3.WriteData(Common.lightList[(int)LIGHT_ENUM.左工位3下同轴光].Chanel, Common.lightList[(int)LIGHT_ENUM.左工位3下同轴光].Value);
                            Thread.Sleep(50);
                            Machine.SecondComputerSocket.SendStr("Station3_2" + Environment.NewLine);
                            while (Common.strStation3_2 == string.Empty)
                            {
                                Thread.Sleep(10);
                            }
                            Common.strStation3_2 = string.Empty;
                            Common.light3.WriteData(Common.lightList[(int)LIGHT_ENUM.左工位3下同轴光].Chanel, 0);

                            ///第3次拍照
                            Common.light3.WriteData(Common.lightList[(int)LIGHT_ENUM.左工位3下同轴光2].Chanel, Common.lightList[(int)LIGHT_ENUM.左工位3下同轴光2].Value);
                            Thread.Sleep(50);
                            Machine.SecondComputerSocket.SendStr("Station3_3" + Environment.NewLine);
                            while (Common.strStation3_3 == string.Empty)
                            {
                                Thread.Sleep(10);
                            }
                            Common.strStation3_3 = string.Empty;
                            Common.light3.WriteData(Common.lightList[(int)LIGHT_ENUM.左工位3下同轴光2].Chanel, 0);

                            ///////接受量测值
                            Machine.SecondComputerSocket.SendStr("Station3_Calculation" + Environment.NewLine);

                            //接受量测值
                            while (Common.strStation3 == string.Empty)
                            {
                                Thread.Sleep(10);
                            }
                            //string strRightStation3 = string.Empty;
                            strRightStation3 = Common.strStation3;
                            Common.strStation3 = string.Empty;
                            Common.AppendUiLog.Log(strRightStation3, LogType.Alert);

                            //数据融合
                            string[] revData1_1 = strRightStation3.Split(',');
                            MeasureProduct mp_1 = new MeasureProduct();
                            Common.Station2Queue_L.TryDequeue(out mp_1);
                            for (int i = 0; i < revData1_1.Length; i++)
                            {
                                if (revData1_1[i].Contains(":"))
                                {
                                    string FAIName = revData1_1[i].Split(':')[0];
                                    string FAIValue = revData1_1[i].Split(':')[1];
                                    DataItem FAI = new DataItem();
                                    FAI.Name = FAIName;
                                    if (FAIName != "SN")
                                    {
                                        FAI.Value = double.Parse(FAIValue);
                                        FAI.Position = 0;
                                        mp_1.MeasureData.Add(FAI);
                                    }
                                    else
                                    {
                                        mp_1.SN = FAIValue;
                                    }
                                }
                            }
                            //数据入队
                            Common.Station3Queue_L.Enqueue(mp_1);
                            Step3 = Step3 + 1;
                            break;
                        #endregion

                        case 104: //摆臂到放料位置   关闭摆臂真空   打开量测真空吸
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LlaserInitialPos_Lstation7.X2AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X3初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LccdInitialPos_Lstation6.Z5AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ15初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在正限位安全位置，请检查");
                                break;
                            }
                            //TODO X轴移动到放料位
                            pp = Machine.pos_Lrock2PutPos_Lstation5.Clone();
                            pp.isShowY2Position = true;
                            pp.isShowZ6Position = false;
                            pp.AxisPriority = "1";
                            if (MotionControl.AxesMove(pp) == true)
                            {
                                pp = Machine.pos_Lrock2PutPos_Lstation5.Clone();
                                pp.isShowY2Position = false;
                                pp.isShowZ6Position = true;
                                pp.AxisPriority = "1";
                                if (MotionControl.AxesMove(pp) == true)
                                {
                                    Machine.do_量测左上激光载盘吸嘴吸.ON();       ////激光
                                    //Machine.do_量测左CCD旋转工位吸嘴吸.ON();
                                    Thread.Sleep(500);

                                    Machine.do_量测左搬运工位前吸嘴吸.OFF();
                                    Machine.do_量测左搬运工位中吸嘴吸.OFF();
                                    Machine.do_量测左搬运工位后吸嘴吸.OFF();
                                    Thread.Sleep(200);
                                    Step3 = Step3 + 1;
                                }
                            }
                            break;

                        case 105: //摆臂到安全位置   
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LlaserInitialPos_Lstation7.X2AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X3初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LccdInitialPos_Lstation6.Z5AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ15初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在正限位安全位置，请检查");
                                break;
                            }
                            pp = Machine.pos_LrockSaftPos_Lstation5.Clone();
                            pp.isShowY2Position = false;
                            pp.isShowZ6Position = true;
                            pp.AxisPriority = "1";
                            if (MotionControl.AxesMove(pp) == true)
                            {
                                if (MotionControl.AxesMove(Machine.pos_LrockSaftPos_Lstation5))
                                {
                                    Step3 = Step3 + 1;
                                }
                            }
                            break;

                        #region 激光处理
                        case 106:  //移动到激光测试的初始位置
                            if (MotionControl.AxesMove(Machine.pos_LlaserStartPos_Lstation7))
                            {
                                Step3 = Step3 + 1;
                            }
                            break;

                        case 107:   //打开激光触发
                            Machine.SecondComputerSocket.SendStr("LaserStart" + Environment.NewLine);
                            while (Common.strStation4LaserStart != "LaserStart")
                            {
                                Thread.Sleep(10);
                            }
                            Machine.do_左工位点激光触发.ON();
                            Common.strStation4LaserStart = string.Empty;
                            Step3 = Step3 + 1;
                            break;

                        case 108:   //运动到激光测量终点位置
                            if (MotionControl.AxesMove(Machine.pos_LlaserEndPos_Lstation7))
                            {
                                Machine.do_左工位点激光触发.OFF();
                                Step3 = Step3 + 1;
                            }
                            break;

                        case 109: //采图并关闭激光触发
                            Machine.SecondComputerSocket.SendStr("LaserStop" + Environment.NewLine);
                            Step3 = Step3 + 1;
                            break;

                        case 110:    //激光处理
                            if (MotionControl.AxesMove(Machine.pos_LlaserInitialPos_Lstation7))//运动到安全位   
                            {

                                while (Common.strStation4 == string.Empty)
                                {
                                    Thread.Sleep(10);
                                }
                                string strLeftStation4 = string.Empty;
                                strLeftStation4 = Common.strStation4;
                                Common.strStation4 = string.Empty;


                                //数据拆分
                                Common.AppendUiLog.Log(strLeftStation4, LogType.Alert);
                                string[] revData14 = strLeftStation4.Split(',');
                                //数据融合
                                MeasureProduct mp4 = new MeasureProduct();
                                Common.Station3Queue_L.TryDequeue(out mp4);
                                for (int i = 0; i < revData14.Length; i++)
                                {
                                    if (revData14[i].Contains(":"))
                                    {
                                        string FAIName = revData14[i].Split(':')[0];
                                        string FAIValue = revData14[i].Split(':')[1];
                                        DataItem FAI = new DataItem();
                                        FAI.Name = FAIName;
                                        FAI.Value = double.Parse(FAIValue);
                                        FAI.Position = 0;
                                        mp4.MeasureData.Add(FAI);
                                    }
                                }
                                //数据入队
                                Common.Station4Queue_L.Enqueue(mp4);
                                Step3 = Step3 + 1;
                            }
                            break;

                        case 111: //等待激光处理结果并轴回到初始位
                            if (MotionControl.CheckMoveDone(Machine.pos_LlaserInitialPos_Lstation7))
                            {
                                Step3 = Step3 + 1;
                            }
                            break;
                        #endregion

                        case 112: //摆臂到取料位置   打开摆臂右吸气     关闭量测真空
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LlaserInitialPos_Lstation7.X2AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X3初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LccdInitialPos_Lstation6.Z5AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ15初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在正限位安全位置，请检查");
                                break;
                            }

                            pp = Machine.pos_LrockInitialPos_Lstation5.Clone();
                            pp.isShowY2Position = false;
                            pp.isShowZ6Position = true;
                            pp.AxisPriority = "1";
                            if (MotionControl.AxesMove(pp) == true)
                            {
                                //走Y
                                pp = Machine.pos_Lrock2FetchPos_Lstation5.Clone();
                                pp.isShowY2Position = true;
                                pp.isShowZ6Position = false;
                                pp.AxisPriority = "1";
                                if (MotionControl.AxesMove(pp) == true)
                                {
                                    //走Z
                                    pp = Machine.pos_Lrock2FetchPos_Lstation5.Clone();
                                    pp.isShowY2Position = false;
                                    pp.isShowZ6Position = true;
                                    pp.AxisPriority = "1";
                                    if (MotionControl.AxesMove(pp))
                                    {
                                        Machine.do_量测左搬运工位后吸嘴吸.ON();
                                        Thread.Sleep(500);

                                        Machine.do_量测左定位机构载盘吸嘴吸.OFF();
                                        Machine.do_量测左上CCD载盘吸嘴吸.OFF();
                                        Machine.do_量测左上激光载盘吸嘴吸.OFF();
                                        Machine.do_量测左CCD旋转工位吸嘴吸.OFF();
                                        Thread.Sleep(200);
                                        Step3 = Step3 + 1;
                                    }
                                }
                            }
                            break;

                        case 113: //摆臂Z轴提升到安全位置
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LlaserInitialPos_Lstation7.X2AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X3初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LccdInitialPos_Lstation6.Z5AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ15初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在正限位安全位置，请检查");
                                break;
                            }
                            pp = Machine.pos_LrockInitialPos_Lstation5.Clone();
                            pp.isShowY2Position = false;
                            pp.isShowZ6Position = true;
                            pp.AxisPriority = "1";
                            if (MotionControl.AxesMove(pp) == true)
                            {
                                Step3 = Step3 + 1;
                            }
                            break;

                        case 114: //摆臂到放料位置   关闭摆臂真空   打开量测真空吸
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LlaserInitialPos_Lstation7.X2AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X3初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LccdInitialPos_Lstation6.Z5AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ15初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在正限位安全位置，请检查");
                                break;
                            }
                            //TODO X轴移动到放料位
                            pp = Machine.pos_Lrock2PutPos_Lstation5.Clone();
                            pp.isShowY2Position = true;
                            pp.isShowZ6Position = false;
                            pp.AxisPriority = "1";
                            if (MotionControl.AxesMove(pp) == true)
                            {
                                pp = Machine.pos_Lrock2PutPos_Lstation5.Clone();
                                pp.isShowY2Position = false;
                                pp.isShowZ6Position = true;
                                pp.AxisPriority = "1";
                                if (MotionControl.AxesMove(pp) == true)
                                {
                                    Machine.do_量测左CCD旋转工位吸嘴吸.ON();
                                    Thread.Sleep(500);

                                    Machine.do_量测左搬运工位前吸嘴吸.OFF();
                                    Machine.do_量测左搬运工位中吸嘴吸.OFF();
                                    Machine.do_量测左搬运工位后吸嘴吸.OFF();
                                    Thread.Sleep(200);
                                    Step3 = Step3 + 1;
                                }
                            }
                            break;

                        case 115: //摆臂到安全位置   
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LlaserInitialPos_Lstation7.X2AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X3初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_LccdInitialPos_Lstation6.Z5AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ15初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在正限位安全位置，请检查");
                                break;
                            }
                            pp = Machine.pos_LrockSaftPos_Lstation5.Clone();
                            pp.isShowY2Position = false;
                            pp.isShowZ6Position = true;
                            pp.AxisPriority = "1";
                            if (MotionControl.AxesMove(pp) == true)
                            {
                                if (MotionControl.AxesMove(Machine.pos_LrockSaftPos_Lstation5))
                                {
                                    Step3 = Step3 + 1;
                                }
                            }
                            break;

                        #region 旋转工位拍照计算   下料机械手取料完成
                        case 116:
                            //TODO 旋转45°
                            if (MotionControl.AxesMove(Machine.pos_Lrotate1Pos_Lstation8) == true)
                            {
                                Step3 = Step3 + 1;
                            }
                            break;

                        case 117:  //第一次拍照
                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.左工位5侧背光].Chanel, Common.lightList[(int)LIGHT_ENUM.左工位5侧背光].Value);
                            //第一次拍照指令
                            Machine.SecondComputerSocket.SendStr("Station5,1" + Environment.NewLine);
                            while (Common.strStation5_1 != "Station5,1")
                            {
                                Thread.Sleep(10);
                            }
                            Common.strStation5_1 = "";
                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.左工位5侧背光].Chanel, 0);
                            Step3 = Step3 + 1;
                            break;

                        case 118:  //调用计算的视觉算子
                            Machine.SecondComputerSocket.SendStr("Station5_1_Calculation" + Environment.NewLine);
                            while (Common.strStation5_Cam1OK != "Cam1OK")
                            {
                                Thread.Sleep(10);
                            }
                            Common.strStation5_Cam1OK = "";
                            Step3 = Step3 + 1;
                            break;

                        case 119:
                            //TODO 旋转45°
                            if (MotionControl.AxesMove(Machine.pos_Lrotate2Pos_Lstation8) == true)
                            {
                                Step3 = Step3 + 1;
                            }
                            break;

                        case 120: //第二次拍照
                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.左工位5侧背光].Chanel, Common.lightList[(int)LIGHT_ENUM.左工位5侧背光].Value);
                            Thread.Sleep(50);
                            Machine.SecondComputerSocket.SendStr("Station5,2" + Environment.NewLine);
                            while (Common.strStation5_2 != "Station5,2")
                            {
                                Thread.Sleep(10);
                            }
                            Common.strStation5_2 = "";
                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.左工位5侧背光].Chanel, 0);
                            Step3 = Step3 + 1;
                            break;

                        case 121:
                            Machine.SecondComputerSocket.SendStr("Station5_2_Calculation" + Environment.NewLine);
                            while (Common.strStation5_Cam2OK != "Cam2OK")
                            {
                                Thread.Sleep(10);
                            }
                            Common.strStation5_Cam2OK = "";
                            Step3 = Step3 + 1;
                            break;

                        case 122:
                            //TODO 旋转45°
                            if (MotionControl.AxesMove(Machine.pos_Lrotate3Pos_Lstation8) == true)
                            {
                                Step3 = Step3 + 1;
                            }
                            break;

                        case 123:  //第三次拍照
                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.左工位5侧背光].Chanel, Common.lightList[(int)LIGHT_ENUM.左工位5侧背光].Value);
                            Thread.Sleep(50);
                            Machine.SecondComputerSocket.SendStr("Station5,3" + Environment.NewLine);
                            while (Common.strStation5_3 != "Station5,3")
                            {
                                Thread.Sleep(10);
                            }
                            Common.strStation5_3 = "";
                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.左工位5侧背光].Chanel, 0);
                            Step3 = Step3 + 1;
                            break;

                        case 124:
                            Machine.SecondComputerSocket.SendStr("Station5_3_Calculation" + Environment.NewLine);
                            while (Common.strStation5_Cam3OK != "Cam3OK")
                            {
                                Thread.Sleep(10);
                            }
                            Common.strStation5_Cam3OK = "";
                            Step3 = Step3 + 1;
                            break;

                        case 125:
                            //TODO 旋转45°
                            if (MotionControl.AxesMove(Machine.pos_Lrotate4Pos_Lstation8) == true)
                            {
                                Step3 = Step3 + 1;
                            }
                            break;

                        case 126:// 第4次拍照
                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.左工位5侧背光].Chanel, Common.lightList[(int)LIGHT_ENUM.左工位5侧背光].Value);
                            Thread.Sleep(50);
                            Machine.SecondComputerSocket.SendStr("Station5,4" + Environment.NewLine);
                            while (Common.strStation5_4 != "Station5,4")
                            {
                                Thread.Sleep(10);
                            }
                            Common.strStation5_4 = "";
                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.左工位5侧背光].Chanel, 0);
                            Step3 = Step3 + 1;
                            break;

                        case 127:
                            Machine.SecondComputerSocket.SendStr("Station5_4_Calculation" + Environment.NewLine);
                            while (Common.strStation5_Cam4OK != "Cam4OK")
                            {
                                Thread.Sleep(10);
                            }
                            Common.strStation5_Cam4OK = "";
                            Step3 = Step3 + 1;
                            break;

                        case 128:    //旋转轴转到初始位置
                            MotionControl.AxesMoveNoWait(Machine.pos_LrotateInitialPos_Lstation8);//异步运动到安全位
                            Step3 = Step3 + 1;
                            break;

                        case 129:
                            Machine.SecondComputerSocket.SendStr("Station5_Calculation" + Environment.NewLine);
                            while (Common.strStation5 == string.Empty)
                            {
                                Thread.Sleep(10);
                            }
                            //string strLeftStation5_1 = string.Empty;

                            strLeftStation5 = Common.strStation5;
                            Common.strStation5 = string.Empty;
                            Common.AppendUiLog.Log(strLeftStation5, LogType.Alert);

                            //数据融合
                            string[] revData15_11 = strLeftStation5.Split(',');
                            MeasureProduct mp5_11 = new MeasureProduct();
                            Common.Station4Queue_L.TryDequeue(out mp5_11);

                            mp5_11.Position = "0";
                            for (int i = 0; i < revData15_11.Length; i++)
                            {
                                if (revData15_11[i].Contains(":"))
                                {
                                    string FAIName = revData15_11[i].Split(':')[0];
                                    string FAIValue = revData15_11[i].Split(':')[1];
                                    DataItem FAI = new DataItem();
                                    FAI.Name = FAIName;
                                    FAI.Value = double.Parse(FAIValue);
                                    FAI.Position = 0;
                                    mp5_11.MeasureData.Add(FAI);
                                }
                            }
                            //数据入队
                            Common.Station5Queue_L.Enqueue(mp5_11);
                            Step3 = Step3 + 1;
                            break;

                        case 130:      //整合产品的数据
                            MeasureProduct mp1_11 = new MeasureProduct();
                            Common.Station5Queue_L.TryDequeue(out mp1_11);
                            JUDGEMENT_RESULT ret11 = ProcessData.PrcessData(mp1_11);
                            string result11 = "";
                            if (ret11 == JUDGEMENT_RESULT.OK)
                            {
                                Machine.SecondComputerSocket.SendStr("ResultOK" + Environment.NewLine);
                                result11 = "OK";
                            }
                            else
                            {
                                Machine.SecondComputerSocket.SendStr("ResultNG" + Environment.NewLine);
                                result11 = "NG";
                            }
                            LMergedDataFininshed = true;
                            Step3 = Step3 + 1;
                            break;

                        case 131:   //等待旋转轴转到初始位置
                            if (MotionControl.CheckMoveDone(Machine.pos_LrotateInitialPos_Lstation8))
                            {
                                Step3 = Step3 + 1;
                            }
                            break;

                        case 132:    //发送允许下料机械手取料的信号
                            if (Common.resultLeft == true && Common.isResultLeftRefresh == true)
                            {
                                Machine.do_给下工位左产品OK信号.ON();
                            }
                            else if (Common.resultLeft == false && Common.isResultLeftRefresh == true)
                            {
                                Machine.do_给下工位左产品NG信号.ON();
                            }
                            Step3 = Step3 + 1;
                            break;

                        case 133:     // //等待下料机械手到位,给破真空完成信号
                            if (Machine.di_下料机左机械手到位信号.GetStatus() == true)
                            {
                                Machine.do_量测左CCD旋转工位吸嘴吸.OFF();
                                Thread.Sleep(100);
                                Machine.do_给下料机左破真空完成.ON();
                                Step3 = Step3 + 1;
                            }
                            break;

                        case 134:     //等待下料机械手取料完成信号
                            if (Machine.di_下料左取料完成.GetStatus() == true || Common.DownLeftRobotTakFinish == true)
                            {
                                Machine.do_给下料机左破真空完成.OFF();
                                Machine.do_给下工位左产品OK信号.OFF();
                                Machine.do_给下工位左产品NG信号.OFF();
                                Step3 = 56;
                            }
                            break;
                        #endregion

                        #endregion

                        #region 上料清料
                        case 56:     //触发左上料进盘清料 
                            Common.Clear左上料进盘 = true;
                            Step3 = Step3 + 1;
                            break;

                        case 57:  //等待上料进盘清料完成
                            if (Common.Clear左上料进盘完成 == true)
                            {
                                Common.Clear左上料收盘完成 = false;
                                Step3 = Step3 + 1;
                            }
                            break;

                        case 58:     //触发左上料收盘清料 
                            Common.Clear左上料收盘 = true;
                            Step3 = Step3 + 1;
                            break;

                        case 59:  //等待左上料收盘清料完成
                            if (Common.Clear左上料收盘完成 == true)
                            {
                                Common.Clear左上料收盘完成 = false;
                                Step3 = Step3 + 1;
                            }
                            break;
                        #endregion

                        #region NGtry清料
                        case 60:     //触发左上料收盘清料 
                            Common.Clear左NG盘 = true;
                            Step3 = Step3 + 1;
                            break;

                        case 61:  //等待左上料收盘清料完成
                            if (Common.Clear左NG盘完成 == true)
                            {
                                Common.Clear左NG盘完成 = false;
                                Step3 = Step3 + 1;
                            }
                            break;
                        #endregion

                        case 62:  //清料完成
                            MessageBox.Show("english:Left Clear Finish--Chinese:左穴清料完成");
                            Common.LeftClearing = false;
                            LeftClearFinish = true;
                            Left_MeasurementUpCCD.Instance.haveProduct = false;
                            Left_MeasurementLaser.Instance.haveProduct = false;
                            Step3 = 0;
                            break;
                    }
                }
            }
        }
        private void RightClera()
        {
            while (true)
            {
                Thread.Sleep(10);
                if (RightClearFinish == true)
                {
                    RightClearFinish = false;
                    break;
                }

                if (MachineStatusManager.CurrentMachineStatus == MachineStatus.Running)
                {
                    switch (Step4)
                    {
                        case 1:
                            //判定是否满足清料条件
                            if (Right_MeasurementLocation.isAllowClear == true && Right_MeasurementRotate.isAllowClear == true
                                 && RightSwingArm_MeasurementStation.isAllowClear == true)
                            {
                                Right_MeasurementLocation.isAllowClear = false;
                                Right_MeasurementRotate.isAllowClear = false;
                                RightSwingArm_MeasurementStation.isAllowClear = false;
                                Common.RightClearing = true;
                                //Common.LowPower = true;

                                if (Right_MeasurementUpCCD.count == 1)//清一颗料
                                {
                                    Right_MeasurementUpCCD.count = 0;
                                    Step4 = 100;
                                }
                                else//清2颗以上的料
                                {
                                    Right_MeasurementUpCCD.count = 0;
                                    Step4 = Step4 + 1;
                                }
                            }
                            else
                            {
                                MessageBox.Show("设备右穴状态不满足清料!");
                                return;
                            }
                            break;

                        case 2: //摆臂到取料位置   打开摆臂中后吸气     关闭量测真空
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RlaserInitialPos_Rstation7.X4AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X4初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RccdInitialPos_Rstation6.Z11AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ14初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在正限位安全位置，请检查");
                                break;
                            }
                            //抬升安全Z
                            pp = Machine.pos_RrockInitialPos_Rstation5.Clone();
                            pp.isShowY4Position = false;
                            pp.isShowZ12Position = true;
                            pp.AxisPriority = "1";
                            if (MotionControl.AxesMove(pp) == true)
                            {
                                //走Y
                                pp = Machine.pos_Rrock2FetchPos_Rstation5.Clone();
                                pp.isShowY4Position = true;
                                pp.isShowZ12Position = false;
                                pp.AxisPriority = "1";
                                if (MotionControl.AxesMove(pp) == true)
                                {
                                    //走Z
                                    pp = Machine.pos_Rrock2FetchPos_Rstation5.Clone();
                                    pp.isShowY4Position = false;
                                    pp.isShowZ12Position = true;
                                    pp.AxisPriority = "1";
                                    if (MotionControl.AxesMove(pp) == true)
                                    {
                                        Machine.do_量测右搬运工位中吸嘴吸.ON();
                                        Machine.do_量测右搬运工位后吸嘴吸.ON();
                                        Thread.Sleep(500);

                                        Machine.do_量测右定位机构载盘吸嘴吸.OFF();
                                        Machine.do_量测右上CCD载盘吸嘴吸.OFF();
                                        Machine.do_量测右上激光载盘吸嘴吸.OFF();
                                        Machine.do_量测右CCD旋转工位吸嘴吸.OFF();
                                        Thread.Sleep(200);
                                        Step4 = Step4 + 1;
                                    }
                                }
                            }
                            break;

                        case 3: //摆臂Z轴提升到安全位置
                            pp = Machine.pos_RrockInitialPos_Rstation5.Clone();
                            pp.isShowY4Position = false;
                            pp.isShowZ12Position = true;
                            pp.AxisPriority = "1";
                            if (MotionControl.AxesMove(pp) == true)
                            {
                                Step4 = Step4 + 1;
                            }
                            break;

                        #region 下CCD拍照处理
                        case 4:  //如果需要下CCD拍照则移动到下CCD 拍照位置  
                            if (MotionControl.AxesMove(Machine.pos_Rrock2BottomCCDPos_Rstation5))
                            {
                                Step4 = Step4 + 1;
                            }
                            break;

                        case 5:
                            string strLeftStation3 = string.Empty;
                            Common.light3.WriteData(Common.lightList[(int)LIGHT_ENUM.右工位3下同轴光SN].Chanel, Common.lightList[(int)LIGHT_ENUM.右工位3下同轴光SN].Value);
                            Thread.Sleep(50);
                            ///第一次拍照
                            try
                            {
                                Reng = new VisionPlatform.VisionManager.Engine("Station3_Capture");
                                Reng.SetInputString("Index", "1");
                                Reng.SetInputNumber("Type", Common.ProductType);
                                Reng.ActionFun();
                                strLeftStation3 = Reng.GetOutputString("CmdResult");

                                while (strLeftStation3 != "Station3,1")
                                {
                                    Thread.Sleep(5);
                                }
                                Common.AppendUiLog.Log(strLeftStation3, LogType.Alert);
                                strLeftStation3 = string.Empty;

                                Reng = null;
                            }
                            catch
                            {
                                Common.AppendUiLog.Log("左工位3第一次拍照异常...", LogType.Error);
                            }
                            Common.light3.WriteData(Common.lightList[(int)LIGHT_ENUM.右工位3下同轴光SN].Chanel, 0);

                            //发送第2次拍照
                            Common.light3.WriteData(Common.lightList[(int)LIGHT_ENUM.右工位3下同轴光].Chanel, Common.lightList[(int)LIGHT_ENUM.右工位3下同轴光].Value);

                            try
                            {
                                Reng = new VisionPlatform.VisionManager.Engine("Station3_Capture");
                                Reng.SetInputString("Index", "2");
                                Reng.SetInputNumber("Type", Common.ProductType);
                                Reng.ActionFun();
                                strLeftStation3 = Reng.GetOutputString("CmdResult");

                                while (strLeftStation3 != "Station3,2")
                                {
                                    Thread.Sleep(5);
                                }
                                Common.AppendUiLog.Log(strLeftStation3, LogType.Alert);
                                strLeftStation3 = string.Empty;

                                Reng = null;
                            }
                            catch
                            {
                                Common.AppendUiLog.Log("左工位3第2次拍照异常...", LogType.Error);
                            }
                            Common.light3.WriteData(Common.lightList[(int)LIGHT_ENUM.右工位3下同轴光].Chanel, 0);

                            //发送第3次拍照
                            Common.light3.WriteData(Common.lightList[(int)LIGHT_ENUM.右工位3下同轴光2].Chanel, Common.lightList[(int)LIGHT_ENUM.右工位3下同轴光2].Value);
                            Thread.Sleep(50);
                            try
                            {
                                Reng = new VisionPlatform.VisionManager.Engine("Station3_Capture");
                                Reng.SetInputString("Index", "3");
                                Reng.SetInputNumber("Type", Common.ProductType);
                                Reng.ActionFun();
                                strLeftStation3 = Reng.GetOutputString("CmdResult");

                                while (strLeftStation3 != "Station3,3")
                                {
                                    Thread.Sleep(5);
                                }
                                Common.AppendUiLog.Log(strLeftStation3, LogType.Alert);
                                strLeftStation3 = string.Empty;

                                Reng = null;
                            }
                            catch
                            {
                                Common.AppendUiLog.Log("左工位3第3次拍照异常...", LogType.Error);
                            }
                            Common.light3.WriteData(Common.lightList[(int)LIGHT_ENUM.右工位3下同轴光2].Chanel, 0);

                            //获取结果
                            try
                            {
                                //不同类型产品调用不同的算法
                                if (Common.ProductType == -1)
                                {
                                    Reng = new VisionPlatform.VisionManager.Engine("Station3");
                                }
                                else if (Common.ProductType == 1)
                                {
                                    Reng = new VisionPlatform.VisionManager.Engine("Station3_Min");
                                }
                                else if (Common.ProductType == 2)
                                {
                                    Reng = new VisionPlatform.VisionManager.Engine("Station3_Mid");
                                }
                                else if (Common.ProductType == 3)
                                {
                                    Reng = new VisionPlatform.VisionManager.Engine("Station3_Max");
                                }
                                Reng.ActionFun();
                                strLeftStation3 = Reng.GetOutputString("Station3Result");
                                Reng = null;
                            }
                            catch
                            {
                                //strLeftStation3 = "LeftStation3OK" + "," + "SN:" + "Test";
                            }
                            //数据融合
                            string[] revData13 = strLeftStation3.Split(',');
                            MeasureProduct mp = new MeasureProduct();
                            Common.Station2Queue_R.TryDequeue(out mp);
                            for (int i = 0; i < revData13.Length; i++)
                            {
                                if (revData13[i].Contains(":"))
                                {
                                    string FAIName = revData13[i].Split(':')[0];
                                    string FAIValue = revData13[i].Split(':')[1];
                                    DataItem FAI = new DataItem();
                                    FAI.Name = FAIName;
                                    if (FAIName != "SN")
                                    {
                                        FAI.Value = double.Parse(FAIValue);
                                        FAI.Position = 0;
                                        mp.MeasureData.Add(FAI);
                                    }
                                    else
                                    {
                                        mp.SN = FAIValue;
                                    }
                                }
                            }
                            //数据入队
                            Common.Station3Queue_R.Enqueue(mp);
                            Step4 = Step4 + 1;
                            break;
                        #endregion

                        case 6: //摆臂到放料位置   关闭摆臂真空   打开量测真空吸
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RlaserInitialPos_Rstation7.X4AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X4初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RccdInitialPos_Rstation6.Z11AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ14初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在正限位安全位置，请检查");
                                break;
                            }
                            //TODO X轴移动到放料位
                            pp = Machine.pos_Rrock2PutPos_Rstation5.Clone();
                            pp.isShowY4Position = true;
                            pp.isShowZ12Position = false;
                            pp.AxisPriority = "1";
                            if (MotionControl.AxesMove(pp) == true)
                            {
                                pp = Machine.pos_Rrock2PutPos_Rstation5.Clone();
                                pp.isShowY4Position = false;
                                pp.isShowZ12Position = true;
                                pp.AxisPriority = "1";
                                if (MotionControl.AxesMove(pp) == true)
                                {
                                    Machine.do_量测右上激光载盘吸嘴吸.ON();       ////激光
                                    Machine.do_量测右CCD旋转工位吸嘴吸.ON();
                                    Thread.Sleep(500);

                                    Machine.do_量测右搬运工位前吸嘴吸.OFF();
                                    Machine.do_量测右搬运工位中吸嘴吸.OFF();
                                    Machine.do_量测右搬运工位后吸嘴吸.OFF();
                                    Thread.Sleep(200);

                                    Step4 = Step4 + 1;
                                }
                            }
                            break;

                        case 7: //摆臂到安全位置   
                            pp = Machine.pos_RrockSaftPos_Rstation5.Clone();
                            pp.isShowY4Position = false;
                            pp.isShowZ12Position = true;
                            pp.AxisPriority = "1";
                            if (MotionControl.AxesMove(pp) == true)
                            {
                                pp = Machine.pos_RrockSaftPos_Rstation5.Clone();
                                pp.isShowY4Position = true;
                                pp.isShowZ12Position = false;
                                pp.AxisPriority = "1";
                                if (MotionControl.AxesMove(pp))
                                {
                                    Step4 = Step4 + 1;
                                }
                            }
                            break;
                        #region 激光处理

                        case 8:  //移动到激光测试的初始位置
                            if (MotionControl.AxesMove(Machine.pos_RlaserStartPos_Rstation7))
                            {
                                Step4 = Step4 + 1;
                            }
                            break;

                        case 9:   //打开激光触发
                            HOperatorSet.GrabImageStart(Common.LMILeftAcqHandle, -1);
                            Machine.do_右工位点激光触发.ON();
                            Common.strStation4LaserStart = string.Empty;
                            Step4 = Step4 + 1;
                            break;

                        case 10:   //运动到激光测量终点位置
                            if (MotionControl.AxesMove(Machine.pos_RlaserEndPos_Rstation7))
                            {
                                Machine.do_右工位点激光触发.OFF();
                                Step4 = Step4 + 1;
                            }
                            break;

                        case 11:     //采图并关闭激光触发
                            HOperatorSet.GrabImageAsync(out RaserImage, Common.LMILeftAcqHandle, -1);
                            Common.Gocator1.system.Stop();
                            Common.Gocator1.system.ClearData();
                            Step4 = Step4 + 1;
                            break;

                        case 12:    //激光处理
                            if (MotionControl.AxesMove(Machine.pos_RlaserInitialPos_Rstation7))//运动到安全位
                            {
                                string strLeftStation4 = string.Empty;
                                HImage image1 = new HImage();
                                HImage image2 = new HImage();
                                try
                                {
                                    Reng = new VisionPlatform.VisionManager.Engine("Station4");
                                    Reng.SetInputImage("Image_3D", new HImage(RaserImage).Decompose3(out image1, out image2));
                                    Reng.ActionFun();
                                    strLeftStation4 = Reng.GetOutputString("Station4Result");
                                    Common.LaserImage = Reng.GetOutputImage("ImageOrg");
                                }
                                catch
                                {
                                    strLeftStation4 = "LeftLaserStop" + "," + "FAI2:" + 9999;
                                }

                                //数据拆分
                                Common.AppendUiLog.Log(strLeftStation4, LogType.Alert);
                                string[] revData14 = strLeftStation4.Split(',');
                                //数据融合
                                MeasureProduct mp4 = new MeasureProduct();
                                Common.Station3Queue_R.TryDequeue(out mp4);
                                for (int i = 0; i < revData14.Length; i++)
                                {
                                    if (revData14[i].Contains(":"))
                                    {
                                        string FAIName = revData14[i].Split(':')[0];
                                        string FAIValue = revData14[i].Split(':')[1];
                                        DataItem FAI = new DataItem();
                                        FAI.Name = FAIName;
                                        try
                                        {
                                            FAI.Value = double.Parse(FAIValue);
                                        }
                                        catch
                                        {
                                            FAI.Value = 9999;
                                        }
                                        FAI.Position = 0;
                                        mp4.MeasureData.Add(FAI);
                                    }
                                }
                                //数据入队
                                Common.Station4Queue_R.Enqueue(mp4);
                                Step4 = Step4 + 1;
                            }
                            break;

                        case 13: //等待激光处理结果并轴回到初始位
                            if (MotionControl.CheckMoveDone(Machine.pos_RlaserInitialPos_Rstation7))
                            {
                                Step4 = Step4 + 1;
                            }
                            break;
                        #endregion

                        #region 旋转工位拍照计算  下料机械手取料完成
                        case 14:
                            //TODO 旋转45°
                            if (MotionControl.AxesMove(Machine.pos_Rrotate1Pos_Rstation8) == true)
                            {
                                Step4 = Step4 + 1;
                            }
                            break;

                        case 15:  //第一次拍照
                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.右工位5侧背光].Chanel, Common.lightList[(int)LIGHT_ENUM.右工位5侧背光].Value);
                            Thread.Sleep(50);
                            string cord = string.Empty;
                            try
                            {
                                Reng = new VisionPlatform.VisionManager.Engine("Station5_Capture");
                                Reng.SetInputString("Index", "1");
                                Reng.SetInputNumber("Type", Common.ProductType);
                                Reng.ActionFun();
                                cord = Reng.GetOutputString("CmdResult");
                                Reng = null;
                            }
                            catch
                            {
                                cord = "Station5,1";
                                Common.AppendUiLog.Log("工位5第一次拍照异常...", LogType.Error);
                            }

                            while (cord != "Station5,1")
                            {
                                Thread.Sleep(5);
                            }

                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.右工位5侧背光].Chanel, 0);
                            Step4 = Step4 + 1;
                            break;

                        case 16:  //调用计算的视觉算子
                            try
                            {
                                Reng_Cal_1 = new VisionPlatform.VisionManager.Engine("Station5");
                                Reng_Cal_1.SetInputString("Index", "1");
                                Reng_Cal_1.ActionFun();
                                cord = Reng_Cal_1.GetOutputString("StationResult");
                            }
                            catch
                            {
                                cord = "Finish,1";
                            }

                            while (cord != "Finish,1")
                            {
                                Thread.Sleep(5);
                            }
                            Step4 = Step4 + 1;
                            break;

                        case 17:
                            //TODO 旋转45°
                            if (MotionControl.AxesMove(Machine.pos_Rrotate2Pos_Rstation8) == true)
                            {
                                Step4 = Step4 + 1;
                            }
                            break;

                        case 18: //第二次拍照
                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.右工位5侧背光].Chanel, Common.lightList[(int)LIGHT_ENUM.右工位5侧背光].Value);
                            //第二次拍照指令
                            Thread.Sleep(50);
                            cord = string.Empty;
                            try
                            {
                                Reng = new VisionPlatform.VisionManager.Engine("Station5_Capture");
                                Reng.SetInputString("Index", "2");
                                Reng.SetInputNumber("Type", Common.ProductType);
                                Reng.ActionFun();
                                cord = Reng.GetOutputString("CmdResult");
                                Reng = null;
                            }
                            catch
                            {
                                cord = "Station5_2";
                                Common.AppendUiLog.Log("工位5第二次拍照异常...", LogType.Error);
                            }

                            while (cord != "Station5,2")
                            {
                                Thread.Sleep(5);
                            }

                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.右工位5侧背光].Chanel, 0);
                            Step4 = Step4 + 1;
                            break;

                        case 19:
                            try
                            {
                                Reng_Cal_2 = new VisionPlatform.VisionManager.Engine("Station5");
                                Reng_Cal_2.SetInputString("Index", "2");
                                Reng_Cal_2.ActionFun();
                                cord = Reng_Cal_2.GetOutputString("StationResult");
                            }
                            catch
                            {
                                cord = "Finish,2";
                            }

                            while (cord != "Finish,2")
                            {
                                Thread.Sleep(5);
                            }
                            Step4 = Step4 + 1;
                            break;

                        case 20:
                            //TODO 旋转45°
                            if (MotionControl.AxesMove(Machine.pos_Rrotate3Pos_Rstation8) == true)
                            {
                                Step4 = Step4 + 1;
                            }
                            break;

                        case 21:  //第三次拍照
                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.右工位5侧背光].Chanel, Common.lightList[(int)LIGHT_ENUM.右工位5侧背光].Value);
                            Thread.Sleep(50);
                            cord = string.Empty;
                            try
                            {
                                Reng = new VisionPlatform.VisionManager.Engine("Station5_Capture");
                                Reng.SetInputString("Index", "3");
                                Reng.SetInputNumber("Type", Common.ProductType);
                                Reng.ActionFun();
                                cord = Reng.GetOutputString("CmdResult");
                                Reng = null;
                            }
                            catch
                            {
                                cord = "Station5,3";
                            }

                            while (cord != "Station5,3")
                            {
                                Thread.Sleep(5);
                            }

                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.右工位5侧背光].Chanel, 0);
                            Step4 = Step4 + 1;
                            break;

                        case 22:
                            try
                            {
                                Reng_Cal_3 = new VisionPlatform.VisionManager.Engine("Station5");
                                Reng_Cal_3.SetInputString("Index", "3");
                                Reng_Cal_3.ActionFun();
                                cord = Reng_Cal_3.GetOutputString("StationResult");
                                Common.RoteImage3 = Reng_Cal_3.GetOutputImage("ImageOrg");
                            }
                            catch
                            {
                                cord = "Finish,3";
                            }

                            while (cord != "Finish,3")
                            {
                                Thread.Sleep(5);
                            }
                            Step4 = Step4 + 1;
                            break;

                        case 23:
                            //TODO 旋转45°
                            if (MotionControl.AxesMove(Machine.pos_Rrotate4Pos_Rstation8) == true)
                            {
                                Step4 = Step4 + 1;
                            }
                            break;

                        case 24:// 第4次拍照
                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.右工位5侧背光].Chanel, Common.lightList[(int)LIGHT_ENUM.右工位5侧背光].Value);
                            Thread.Sleep(50);
                            cord = string.Empty;
                            try
                            {
                                Reng = new VisionPlatform.VisionManager.Engine("Station5_Capture");
                                Reng.SetInputString("Index", "4");
                                Reng.SetInputNumber("Type", Common.ProductType);
                                Reng.ActionFun();
                                cord = Reng.GetOutputString("CmdResult");
                                Reng = null;
                            }
                            catch
                            {
                                cord = "Station5,4";
                            }

                            while (cord != "Station5,4")
                            {
                                Thread.Sleep(5);
                            }
                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.右工位5侧背光].Chanel, 0);
                            Step4 = Step4 + 1;
                            break;

                        case 25:
                            try
                            {
                                Reng_Cal_4 = new VisionPlatform.VisionManager.Engine("Station5");
                                Reng_Cal_4.SetInputString("Index", "4");
                                Reng_Cal_4.ActionFun();
                                cord = Reng_Cal_4.GetOutputString("StationResult");
                            }
                            catch
                            {
                                cord = "Finish,4";
                            }

                            while (cord != "Finish,4")
                            {
                                Thread.Sleep(5);
                            }
                            Step4 = Step4 + 1;
                            break;

                        case 26:    //旋转轴转到初始位置
                            MotionControl.AxesMoveNoWait(Machine.pos_RrotateInitialPos_Rstation8);//异步运动到安全位
                            Step4 = Step4 + 1;
                            break;

                        case 27:
                            //发送允许计算指令
                            string strLeftStation5 = string.Empty;

                            while (Reng_Cal_1.GetOutputString("StationResult") != "Finish,1" || Reng_Cal_2.GetOutputString("StationResult") != "Finish,2"
                                        || Reng_Cal_3.GetOutputString("StationResult") != "Finish,3" || Reng_Cal_4.GetOutputString("StationResult") != "Finish,4")
                            {
                                Thread.Sleep(10);
                            }

                            Reng_Cal_1 = null;
                            Reng_Cal_2 = null;
                            Reng_Cal_3 = null;
                            Reng_Cal_4 = null;
                            try
                            {
                                Reng = new VisionPlatform.VisionManager.Engine("DataCaculate FAI5-9");
                                Reng.ActionFun();
                                strLeftStation5 = Reng.GetOutputString("Station5Result");
                            }
                            catch
                            {
                                strLeftStation5 = strLeftStation5 = "LeftStation3OK" + "," + "FAI5:" + 9999 + "," + "FAI6:" + 9999 + "," + "FAI7:" + 9999 + "," + "FAI8:" + 9999 + "," + "FAI9:" + 9999;
                            }

                            //strLeftStation5 = strLeftStation5 = "RightStation3OK" + "," + "FAI5:" + 9999 + "," + "FAI6:" + 9999 + "," + "FAI7:" + 9999 + "," + "FAI8:" + 9999 + "," + "FAI9:" + 9999;
                            Common.AppendUiLog.Log(strLeftStation5, LogType.Alert);

                            //数据融合
                            string[] revData15 = strLeftStation5.Split(',');
                            MeasureProduct mp5 = new MeasureProduct();
                            Common.Station4Queue_R.TryDequeue(out mp5);
                            mp5.Position = "1";
                            for (int i = 0; i < revData15.Length; i++)
                            {
                                if (revData15[i].Contains(":"))
                                {
                                    string FAIName = revData15[i].Split(':')[0];
                                    string FAIValue = revData15[i].Split(':')[1];
                                    DataItem FAI = new DataItem();
                                    FAI.Name = FAIName;
                                    FAI.Value = double.Parse(FAIValue);
                                    FAI.Position = 0;
                                    mp5.MeasureData.Add(FAI);
                                }
                            }
                            //数据入队
                            Common.Station5Queue_R.Enqueue(mp5);
                            Step4 = Step4 + 1;
                            break;

                        case 28:      //整合产品的数据
                            MeasureProduct mp1 = new MeasureProduct();
                            Common.Station5Queue_R.TryDequeue(out mp1);
                            JUDGEMENT_RESULT ret = ProcessData.PrcessData(mp1);
                            Step4 = Step4 + 1;
                            break;

                        case 29:   //等待旋转轴转到初始位置
                            if (MotionControl.CheckMoveDone(Machine.pos_RrotateInitialPos_Rstation8))
                            {
                                Step4 = Step4 + 1;
                            }
                            break;

                        case 30:    //发送允许下料机械手取料的信号
                            if (Common.resultRight == true && Common.isResultRightRefresh == true)
                            {
                                Common.isResultRightRefresh = false;
                                Common.resultRight = null;
                                Machine.do_给下工位右产品OK信号.ON();
                            }
                            else if (Common.resultRight == false && Common.isResultRightRefresh == true)
                            {
                                Common.isResultRightRefresh = false;
                                Common.resultRight = null;
                                Machine.do_给下工位右产品NG信号.ON();
                            }
                            Step4 = Step4 + 1;
                            break;

                        case 31:     // //等待下料机械手到位,给破真空完成信号
                            if (Machine.di_下料机右机械手到位信号.GetStatus() == true)
                            {
                                Machine.do_量测右CCD旋转工位吸嘴吸.OFF();
                                Thread.Sleep(100);
                                Machine.do_给下料机右破真空完成.ON();
                                Step4 = Step4 + 1;
                            }
                            break;

                        case 32:     //等待下料机械手取料完成信号
                            if (Machine.di_下料右取料完成.GetStatus() == true || Common.DownRightRobotTakFinish == true)
                            {
                                Machine.do_给下料机右破真空完成.OFF();
                                Machine.do_给下工位右产品OK信号.OFF();
                                Machine.do_给下工位右产品NG信号.OFF();
                                Step4 = Step4 + 1;
                            }
                            break;
                        #endregion

                        case 33: //摆臂到取料位置   打开摆臂右吸气     关闭量测真空
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RlaserInitialPos_Rstation7.X4AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X4初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RccdInitialPos_Rstation6.Z11AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ14初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在正限位安全位置，请检查");
                                break;
                            }
                            pp = Machine.pos_RrockInitialPos_Rstation5.Clone();
                            pp.isShowY4Position = false;
                            pp.isShowZ12Position = true;
                            pp.AxisPriority = "1";
                            if (MotionControl.AxesMove(pp) == true)
                            {
                                //走Y
                                pp = Machine.pos_Rrock2FetchPos_Rstation5.Clone();
                                pp.isShowY4Position = true;
                                pp.isShowZ12Position = false;
                                pp.AxisPriority = "1";
                                if (MotionControl.AxesMove(pp) == true)
                                {
                                    //走Z
                                    pp = Machine.pos_Rrock2FetchPos_Rstation5.Clone();
                                    pp.isShowY4Position = false;
                                    pp.isShowZ12Position = true;
                                    pp.AxisPriority = "1";
                                    if (MotionControl.AxesMove(pp))
                                    {
                                        Machine.do_量测右搬运工位后吸嘴吸.ON();
                                        Thread.Sleep(500);

                                        Machine.do_量测右定位机构载盘吸嘴吸.OFF();
                                        Machine.do_量测右上CCD载盘吸嘴吸.OFF();
                                        Machine.do_量测右上激光载盘吸嘴吸.OFF();
                                        Machine.do_量测右CCD旋转工位吸嘴吸.OFF();
                                        Thread.Sleep(200);
                                        Step4 = Step4 + 1;
                                    }
                                }
                            }
                            break;

                        case 34: //摆臂Z轴提升到安全位置
                            pp = Machine.pos_RrockInitialPos_Rstation5.Clone();
                            pp.isShowY4Position = false;
                            pp.isShowZ12Position = true;
                            pp.AxisPriority = "1";
                            if (MotionControl.AxesMove(pp) == true)
                            {
                                Step4 = Step4 + 1;
                            }
                            break;

                        case 35: //摆臂到放料位置   关闭摆臂真空   打开量测真空吸
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RlaserInitialPos_Rstation7.X4AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X4初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RccdInitialPos_Rstation6.Z11AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ14初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在正限位安全位置，请检查");
                                break;
                            }
                            //TODO X轴移动到放料位
                            pp = Machine.pos_Rrock2PutPos_Rstation5.Clone();
                            pp.isShowY4Position = true;
                            pp.isShowZ12Position = false;
                            pp.AxisPriority = "1";
                            if (MotionControl.AxesMove(pp) == true)
                            {
                                pp = Machine.pos_Rrock2PutPos_Rstation5.Clone();
                                pp.isShowY4Position = false;
                                pp.isShowZ12Position = true;
                                pp.AxisPriority = "1";
                                if (MotionControl.AxesMove(pp) == true)
                                {
                                    Machine.do_量测右CCD旋转工位吸嘴吸.ON();
                                    Thread.Sleep(500);

                                    Machine.do_量测右搬运工位前吸嘴吸.OFF();
                                    Machine.do_量测右搬运工位中吸嘴吸.OFF();
                                    Machine.do_量测右搬运工位后吸嘴吸.OFF();
                                    Thread.Sleep(200);
                                    Step4 = Step4 + 1;
                                }
                            }
                            break;

                        case 36: //摆臂到安全位置   
                            pp = Machine.pos_RrockSaftPos_Rstation5.Clone();
                            pp.isShowY4Position = false;
                            pp.isShowZ12Position = true;
                            pp.AxisPriority = "1";
                            if (MotionControl.AxesMove(pp) == true)
                            {
                                pp = Machine.pos_RrockSaftPos_Rstation5.Clone();
                                pp.isShowY4Position = true;
                                pp.isShowZ12Position = false;
                                pp.AxisPriority = "1";
                                if (MotionControl.AxesMove(pp))
                                {
                                    Step4 = Step4 + 1;
                                }
                            }
                            break;

                        #region 旋转工位拍照计算  下料机械手取料完成
                        case 37:
                            //TODO 旋转45°
                            if (MotionControl.AxesMove(Machine.pos_Rrotate1Pos_Rstation8) == true)
                            {
                                Step4 = Step4 + 1;
                            }
                            break;

                        case 38:  //第一次拍照
                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.右工位5侧背光].Chanel, Common.lightList[(int)LIGHT_ENUM.右工位5侧背光].Value);
                            Thread.Sleep(50);
                            //string cord = string.Empty;
                            try
                            {
                                Reng = new VisionPlatform.VisionManager.Engine("Station5_Capture");
                                Reng.SetInputString("Index", "1");
                                Reng.SetInputNumber("Type", Common.ProductType);
                                Reng.ActionFun();
                                cord = Reng.GetOutputString("CmdResult");
                                Reng = null;
                            }
                            catch
                            {
                                cord = "Station5,1";
                                Common.AppendUiLog.Log("工位5第一次拍照异常...", LogType.Error);
                            }

                            while (cord != "Station5,1")
                            {
                                Thread.Sleep(5);
                            }

                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.右工位5侧背光].Chanel, 0);
                            Step4 = Step4 + 1;
                            break;

                        case 39:  //调用计算的视觉算子
                            try
                            {
                                Reng_Cal_1 = new VisionPlatform.VisionManager.Engine("Station5");
                                Reng_Cal_1.SetInputString("Index", "1");
                                Reng_Cal_1.ActionFun();
                                cord = Reng_Cal_1.GetOutputString("StationResult");
                            }
                            catch
                            {
                                cord = "Finish,1";
                            }

                            while (cord != "Finish,1")
                            {
                                Thread.Sleep(5);
                            }
                            Step4 = Step4 + 1;
                            break;

                        case 40:
                            //TODO 旋转45°
                            if (MotionControl.AxesMove(Machine.pos_Rrotate2Pos_Rstation8) == true)
                            {
                                Step4 = Step4 + 1;
                            }
                            break;

                        case 41: //第二次拍照
                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.右工位5侧背光].Chanel, Common.lightList[(int)LIGHT_ENUM.右工位5侧背光].Value);
                            //第二次拍照指令
                            Thread.Sleep(50);
                            cord = string.Empty;
                            try
                            {
                                Reng = new VisionPlatform.VisionManager.Engine("Station5_Capture");
                                Reng.SetInputString("Index", "2");
                                Reng.SetInputNumber("Type", Common.ProductType);
                                Reng.ActionFun();
                                cord = Reng.GetOutputString("CmdResult");
                                Reng = null;
                            }
                            catch
                            {
                                cord = "Station5_2";
                                Common.AppendUiLog.Log("工位5第二次拍照异常...", LogType.Error);
                            }

                            while (cord != "Station5,2")
                            {
                                Thread.Sleep(5);
                            }

                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.右工位5侧背光].Chanel, 0);
                            Step4 = Step4 + 1;
                            break;

                        case 42:
                            try
                            {
                                Reng_Cal_2 = new VisionPlatform.VisionManager.Engine("Station5");
                                Reng_Cal_2.SetInputString("Index", "2");
                                Reng_Cal_2.ActionFun();
                                cord = Reng_Cal_2.GetOutputString("StationResult");
                            }
                            catch
                            {
                                cord = "Finish,2";
                            }

                            while (cord != "Finish,2")
                            {
                                Thread.Sleep(5);
                            }
                            Step4 = Step4 + 1;
                            break;

                        case 43:
                            //TODO 旋转45°
                            if (MotionControl.AxesMove(Machine.pos_Rrotate3Pos_Rstation8) == true)
                            {
                                Step4 = Step4 + 1;
                            }
                            break;

                        case 44:  //第三次拍照
                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.右工位5侧背光].Chanel, Common.lightList[(int)LIGHT_ENUM.右工位5侧背光].Value);
                            Thread.Sleep(50);
                            cord = string.Empty;
                            try
                            {
                                Reng = new VisionPlatform.VisionManager.Engine("Station5_Capture");
                                Reng.SetInputString("Index", "3");
                                Reng.SetInputNumber("Type", Common.ProductType);
                                Reng.ActionFun();
                                cord = Reng.GetOutputString("CmdResult");
                                Reng = null;
                            }
                            catch
                            {
                                cord = "Station5,3";
                            }

                            while (cord != "Station5,3")
                            {
                                Thread.Sleep(5);
                            }

                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.右工位5侧背光].Chanel, 0);
                            Step4 = Step4 + 1;
                            break;

                        case 45:
                            try
                            {
                                Reng_Cal_3 = new VisionPlatform.VisionManager.Engine("Station5");
                                Reng_Cal_3.SetInputString("Index", "3");
                                Reng_Cal_3.ActionFun();
                                cord = Reng_Cal_3.GetOutputString("StationResult");
                                Common.RoteImage3 = Reng_Cal_3.GetOutputImage("ImageOrg");
                            }
                            catch
                            {
                                cord = "Finish,3";
                            }

                            while (cord != "Finish,3")
                            {
                                Thread.Sleep(5);
                            }
                            Step4 = Step4 + 1;
                            break;

                        case 46:
                            //TODO 旋转45°
                            if (MotionControl.AxesMove(Machine.pos_Rrotate4Pos_Rstation8) == true)
                            {
                                Step4 = Step4 + 1;
                            }
                            break;

                        case 47:// 第4次拍照
                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.右工位5侧背光].Chanel, Common.lightList[(int)LIGHT_ENUM.右工位5侧背光].Value);
                            Thread.Sleep(50);
                            cord = string.Empty;
                            try
                            {
                                Reng = new VisionPlatform.VisionManager.Engine("Station5_Capture");
                                Reng.SetInputString("Index", "4");
                                Reng.SetInputNumber("Type", Common.ProductType);
                                Reng.ActionFun();
                                cord = Reng.GetOutputString("CmdResult");
                                Reng = null;
                            }
                            catch
                            {
                                cord = "Station5,4";
                            }

                            while (cord != "Station5,4")
                            {
                                Thread.Sleep(5);
                            }
                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.右工位5侧背光].Chanel, 0);
                            Step4 = Step4 + 1;
                            break;

                        case 48:
                            try
                            {
                                Reng_Cal_4 = new VisionPlatform.VisionManager.Engine("Station5");
                                Reng_Cal_4.SetInputString("Index", "4");
                                Reng_Cal_4.ActionFun();
                                cord = Reng_Cal_4.GetOutputString("StationResult");
                            }
                            catch
                            {
                                cord = "Finish,4";
                            }

                            while (cord != "Finish,4")
                            {
                                Thread.Sleep(5);
                            }
                            Step4 = Step4 + 1;
                            break;

                        case 49:    //旋转轴转到初始位置
                            MotionControl.AxesMoveNoWait(Machine.pos_RrotateInitialPos_Rstation8);//异步运动到安全位
                            Step4 = Step4 + 1;
                            break;

                        case 50:
                            //发送允许计算指令
                            //string strLeftStation5 = string.Empty;

                            while (Reng_Cal_1.GetOutputString("StationResult") != "Finish,1" || Reng_Cal_2.GetOutputString("StationResult") != "Finish,2"
                                        || Reng_Cal_3.GetOutputString("StationResult") != "Finish,3" || Reng_Cal_4.GetOutputString("StationResult") != "Finish,4")
                            {
                                Thread.Sleep(10);
                            }

                            Reng_Cal_1 = null;
                            Reng_Cal_2 = null;
                            Reng_Cal_3 = null;
                            Reng_Cal_4 = null;
                            try
                            {
                                Reng = new VisionPlatform.VisionManager.Engine("DataCaculate FAI5-9");
                                Reng.ActionFun();
                                strLeftStation5 = Reng.GetOutputString("Station5Result");
                            }
                            catch
                            {
                                strLeftStation5 = strLeftStation5 = "LeftStation3OK" + "," + "FAI5:" + 9999 + "," + "FAI6:" + 9999 + "," + "FAI7:" + 9999 + "," + "FAI8:" + 9999 + "," + "FAI9:" + 9999;
                            }

                            //strLeftStation5 = strLeftStation5 = "RightStation3OK" + "," + "FAI5:" + 9999 + "," + "FAI6:" + 9999 + "," + "FAI7:" + 9999 + "," + "FAI8:" + 9999 + "," + "FAI9:" + 9999;
                            Common.AppendUiLog.Log(strLeftStation5, LogType.Alert);

                            //数据融合
                            string[] revData15_1 = strLeftStation5.Split(',');
                            MeasureProduct mp5_1 = new MeasureProduct();
                            Common.Station4Queue_R.TryDequeue(out mp5_1);
                            mp5_1.Position = "1";
                            for (int i = 0; i < revData15_1.Length; i++)
                            {
                                if (revData15_1[i].Contains(":"))
                                {
                                    string FAIName = revData15_1[i].Split(':')[0];
                                    string FAIValue = revData15_1[i].Split(':')[1];
                                    DataItem FAI = new DataItem();
                                    FAI.Name = FAIName;
                                    FAI.Value = double.Parse(FAIValue);
                                    FAI.Position = 0;
                                    mp5_1.MeasureData.Add(FAI);
                                }
                            }
                            //数据入队
                            Common.Station5Queue_R.Enqueue(mp5_1);
                            Step4 = Step4 + 1;
                            break;

                        case 51:      //整合产品的数据
                            MeasureProduct mp1_1 = new MeasureProduct();
                            Common.Station5Queue_R.TryDequeue(out mp1_1);
                            JUDGEMENT_RESULT ret_1 = ProcessData.PrcessData(mp1_1);
                            Step4 = Step4 + 1;
                            break;

                        case 52:   //等待旋转轴转到初始位置
                            if (MotionControl.CheckMoveDone(Machine.pos_RrotateInitialPos_Rstation8))
                            {
                                Step4 = Step4 + 1;
                            }
                            break;

                        case 53:    //发送允许下料机械手取料的信号
                            if (Common.resultRight == true && Common.isResultRightRefresh == true)
                            {
                                Common.isResultRightRefresh = false;
                                Common.resultRight = null;
                                Machine.do_给下工位右产品OK信号.ON();
                            }
                            else if (Common.resultRight == false && Common.isResultRightRefresh == true)
                            {
                                Common.isResultRightRefresh = false;
                                Common.resultRight = null;
                                Machine.do_给下工位右产品NG信号.ON();
                            }
                            Step4 = Step4 + 1;
                            break;

                        case 54:     // //等待下料机械手到位,给破真空完成信号
                            if (Machine.di_下料机右机械手到位信号.GetStatus() == true)
                            {
                                Machine.do_量测右CCD旋转工位吸嘴吸.OFF();
                                Thread.Sleep(100);
                                Machine.do_给下料机右破真空完成.ON();
                                Step4 = Step4 + 1;
                            }
                            break;

                        case 55:     //等待下料机械手取料完成信号
                            if (Machine.di_下料右取料完成.GetStatus() == true || Common.DownRightRobotTakFinish == true)
                            {
                                Machine.do_给下料机右破真空完成.OFF();
                                Machine.do_给下工位右产品OK信号.OFF();
                                Machine.do_给下工位右产品NG信号.OFF();
                                Step4 = 56;
                            }
                            break;
                        #endregion

                        #region 只有1颗料清料
                        case 100: //摆臂到取料位置   打开摆臂中后吸气     关闭量测真空
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RlaserInitialPos_Rstation7.X4AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X4初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RccdInitialPos_Rstation6.Z11AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ14初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在正限位安全位置，请检查");
                                break;
                            }
                            //抬升安全Z
                            pp = Machine.pos_RrockInitialPos_Rstation5.Clone();
                            pp.isShowY4Position = false;
                            pp.isShowZ12Position = true;
                            pp.AxisPriority = "1";
                            if (MotionControl.AxesMove(pp) == true)
                            {
                                //走Y
                                pp = Machine.pos_Rrock2FetchPos_Rstation5.Clone();
                                pp.isShowY4Position = true;
                                pp.isShowZ12Position = false;
                                pp.AxisPriority = "1";
                                if (MotionControl.AxesMove(pp) == true)
                                {
                                    //走Z
                                    pp = Machine.pos_Rrock2FetchPos_Rstation5.Clone();
                                    pp.isShowY4Position = false;
                                    pp.isShowZ12Position = true;
                                    pp.AxisPriority = "1";
                                    if (MotionControl.AxesMove(pp) == true)
                                    {
                                        Machine.do_量测右搬运工位中吸嘴吸.ON();
                                        Machine.do_量测右搬运工位后吸嘴吸.ON();
                                        Thread.Sleep(500);

                                        Machine.do_量测右定位机构载盘吸嘴吸.OFF();
                                        Machine.do_量测右上CCD载盘吸嘴吸.OFF();
                                        Machine.do_量测右上激光载盘吸嘴吸.OFF();
                                        Machine.do_量测右CCD旋转工位吸嘴吸.OFF();
                                        Thread.Sleep(200);
                                        Step4 = Step4 + 1;
                                    }
                                }
                            }
                            break;

                        case 101: //摆臂Z轴提升到安全位置
                            pp = Machine.pos_RrockInitialPos_Rstation5.Clone();
                            pp.isShowY4Position = false;
                            pp.isShowZ12Position = true;
                            pp.AxisPriority = "1";
                            if (MotionControl.AxesMove(pp) == true)
                            {
                                Step4 = Step4 + 1;
                            }
                            break;

                        #region 下CCD拍照处理
                        case 102:  //如果需要下CCD拍照则移动到下CCD 拍照位置  
                            if (MotionControl.AxesMove(Machine.pos_Rrock2BottomCCDPos_Rstation5))
                            {
                                Step4 = Step4 + 1;
                            }
                            break;

                        case 103:
                            string strLeftStation31 = string.Empty;
                            Common.light3.WriteData(Common.lightList[(int)LIGHT_ENUM.右工位3下同轴光SN].Chanel, Common.lightList[(int)LIGHT_ENUM.右工位3下同轴光SN].Value);
                            Thread.Sleep(50);
                            ///第一次拍照
                            try
                            {
                                Reng = new VisionPlatform.VisionManager.Engine("Station3_Capture");
                                Reng.SetInputString("Index", "1");
                                Reng.SetInputNumber("Type", Common.ProductType);
                                Reng.ActionFun();
                                strLeftStation31 = Reng.GetOutputString("CmdResult");

                                while (strLeftStation31 != "Station3,1")
                                {
                                    Thread.Sleep(5);
                                }
                                Common.AppendUiLog.Log(strLeftStation31, LogType.Alert);
                                strLeftStation31 = string.Empty;

                                Reng = null;
                            }
                            catch
                            {
                                Common.AppendUiLog.Log("左工位3第一次拍照异常...", LogType.Error);
                            }
                            Common.light3.WriteData(Common.lightList[(int)LIGHT_ENUM.右工位3下同轴光SN].Chanel, 0);

                            //发送第2次拍照
                            Common.light3.WriteData(Common.lightList[(int)LIGHT_ENUM.右工位3下同轴光].Chanel, Common.lightList[(int)LIGHT_ENUM.右工位3下同轴光].Value);

                            try
                            {
                                Reng = new VisionPlatform.VisionManager.Engine("Station3_Capture");
                                Reng.SetInputString("Index", "2");
                                Reng.SetInputNumber("Type", Common.ProductType);
                                Reng.ActionFun();
                                strLeftStation31 = Reng.GetOutputString("CmdResult");

                                while (strLeftStation31 != "Station3,2")
                                {
                                    Thread.Sleep(5);
                                }
                                Common.AppendUiLog.Log(strLeftStation31, LogType.Alert);
                                strLeftStation31 = string.Empty;

                                Reng = null;
                            }
                            catch
                            {
                                Common.AppendUiLog.Log("左工位3第2次拍照异常...", LogType.Error);
                            }
                            Common.light3.WriteData(Common.lightList[(int)LIGHT_ENUM.右工位3下同轴光].Chanel, 0);

                            //发送第3次拍照
                            Common.light3.WriteData(Common.lightList[(int)LIGHT_ENUM.右工位3下同轴光2].Chanel, Common.lightList[(int)LIGHT_ENUM.右工位3下同轴光2].Value);
                            Thread.Sleep(50);
                            try
                            {
                                Reng = new VisionPlatform.VisionManager.Engine("Station3_Capture");
                                Reng.SetInputString("Index", "3");
                                Reng.SetInputNumber("Type", Common.ProductType);
                                Reng.ActionFun();
                                strLeftStation31 = Reng.GetOutputString("CmdResult");

                                while (strLeftStation31 != "Station3,3")
                                {
                                    Thread.Sleep(5);
                                }
                                Common.AppendUiLog.Log(strLeftStation31, LogType.Alert);
                                strLeftStation31 = string.Empty;

                                Reng = null;
                            }
                            catch
                            {
                                Common.AppendUiLog.Log("左工位3第3次拍照异常...", LogType.Error);
                            }
                            Common.light3.WriteData(Common.lightList[(int)LIGHT_ENUM.右工位3下同轴光2].Chanel, 0);

                            //获取结果
                            try
                            {
                                //不同类型产品调用不同的算法
                                if (Common.ProductType == -1)
                                {
                                    Reng = new VisionPlatform.VisionManager.Engine("Station3");
                                }
                                else if (Common.ProductType == 1)
                                {
                                    Reng = new VisionPlatform.VisionManager.Engine("Station3_Min");
                                }
                                else if (Common.ProductType == 2)
                                {
                                    Reng = new VisionPlatform.VisionManager.Engine("Station3_Mid");
                                }
                                else if (Common.ProductType == 3)
                                {
                                    Reng = new VisionPlatform.VisionManager.Engine("Station3_Max");
                                }
                                Reng.ActionFun();
                                strLeftStation31 = Reng.GetOutputString("Station3Result");
                                Reng = null;
                            }
                            catch
                            {
                                //strLeftStation3 = "LeftStation3OK" + "," + "SN:" + "Test";
                            }
                            //数据融合
                            string[] revData13_1 = strLeftStation31.Split(',');
                            MeasureProduct mp_1 = new MeasureProduct();
                            Common.Station2Queue_R.TryDequeue(out mp_1);
                            for (int i = 0; i < revData13_1.Length; i++)
                            {
                                if (revData13_1[i].Contains(":"))
                                {
                                    string FAIName = revData13_1[i].Split(':')[0];
                                    string FAIValue = revData13_1[i].Split(':')[1];
                                    DataItem FAI = new DataItem();
                                    FAI.Name = FAIName;
                                    if (FAIName != "SN")
                                    {
                                        FAI.Value = double.Parse(FAIValue);
                                        FAI.Position = 0;
                                        mp_1.MeasureData.Add(FAI);
                                    }
                                    else
                                    {
                                        mp_1.SN = FAIValue;
                                    }
                                }
                            }
                            //数据入队
                            Common.Station3Queue_R.Enqueue(mp_1);

                            Step4 = Step4 + 1;
                            break;
                        #endregion

                        case 104: //摆臂到放料位置   关闭摆臂真空   打开量测真空吸
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RlaserInitialPos_Rstation7.X4AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X4初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RccdInitialPos_Rstation6.Z11AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ14初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在正限位安全位置，请检查");
                                break;
                            }
                            //TODO X轴移动到放料位
                            pp = Machine.pos_Rrock2PutPos_Rstation5.Clone();
                            pp.isShowY4Position = true;
                            pp.isShowZ12Position = false;
                            pp.AxisPriority = "1";
                            if (MotionControl.AxesMove(pp) == true)
                            {
                                pp = Machine.pos_Rrock2PutPos_Rstation5.Clone();
                                pp.isShowY4Position = false;
                                pp.isShowZ12Position = true;
                                pp.AxisPriority = "1";
                                if (MotionControl.AxesMove(pp) == true)
                                {
                                    Machine.do_量测右上激光载盘吸嘴吸.ON();       ////激光
                                    //Machine.do_量测右CCD旋转工位吸嘴吸.ON();
                                    Thread.Sleep(500);

                                    Machine.do_量测右搬运工位前吸嘴吸.OFF();
                                    Machine.do_量测右搬运工位中吸嘴吸.OFF();
                                    Machine.do_量测右搬运工位后吸嘴吸.OFF();
                                    Thread.Sleep(200);

                                    Step4 = Step4 + 1;
                                }
                            }
                            break;

                        case 105: //摆臂到安全位置   
                            pp = Machine.pos_RrockSaftPos_Rstation5.Clone();
                            pp.isShowY4Position = false;
                            pp.isShowZ12Position = true;
                            pp.AxisPriority = "1";
                            if (MotionControl.AxesMove(pp) == true)
                            {
                                pp = Machine.pos_RrockSaftPos_Rstation5.Clone();
                                pp.isShowY4Position = true;
                                pp.isShowZ12Position = false;
                                pp.AxisPriority = "1";
                                if (MotionControl.AxesMove(pp))
                                {
                                    Step4 = Step4 + 1;
                                }
                            }
                            break;
                        #region 激光处理

                        case 106:  //移动到激光测试的初始位置
                            if (MotionControl.AxesMove(Machine.pos_RlaserStartPos_Rstation7))
                            {
                                Step4 = Step4 + 1;
                            }
                            break;

                        case 107:   //打开激光触发
                            HOperatorSet.GrabImageStart(Common.LMILeftAcqHandle, -1);
                            Machine.do_右工位点激光触发.ON();
                            Common.strStation4LaserStart = string.Empty;
                            Step4 = Step4 + 1;
                            break;

                        case 108:   //运动到激光测量终点位置
                            if (MotionControl.AxesMove(Machine.pos_RlaserEndPos_Rstation7))
                            {
                                Machine.do_右工位点激光触发.OFF();
                                Step4 = Step4 + 1;
                            }
                            break;

                        case 109:     //采图并关闭激光触发
                            HOperatorSet.GrabImageAsync(out RaserImage, Common.LMILeftAcqHandle, -1);
                            Common.Gocator1.system.Stop();
                            Common.Gocator1.system.ClearData();
                            Step4 = Step4 + 1;
                            break;

                        case 110:    //激光处理
                            if (MotionControl.AxesMove(Machine.pos_RlaserInitialPos_Rstation7))//运动到安全位
                            {
                                string strLeftStation4 = string.Empty;
                                HImage image1 = new HImage();
                                HImage image2 = new HImage();
                                try
                                {
                                    Reng = new VisionPlatform.VisionManager.Engine("Station4");
                                    Reng.SetInputImage("Image_3D", new HImage(RaserImage).Decompose3(out image1, out image2));
                                    Reng.ActionFun();
                                    strLeftStation4 = Reng.GetOutputString("Station4Result");
                                    Common.LaserImage = Reng.GetOutputImage("ImageOrg");
                                }
                                catch
                                {
                                    strLeftStation4 = "LeftLaserStop" + "," + "FAI2:" + 9999;
                                }

                                //数据拆分
                                Common.AppendUiLog.Log(strLeftStation4, LogType.Alert);
                                string[] revData14 = strLeftStation4.Split(',');
                                //数据融合
                                MeasureProduct mp4 = new MeasureProduct();
                                Common.Station3Queue_R.TryDequeue(out mp4);
                                for (int i = 0; i < revData14.Length; i++)
                                {
                                    if (revData14[i].Contains(":"))
                                    {
                                        string FAIName = revData14[i].Split(':')[0];
                                        string FAIValue = revData14[i].Split(':')[1];
                                        DataItem FAI = new DataItem();
                                        FAI.Name = FAIName;
                                        try
                                        {
                                            FAI.Value = double.Parse(FAIValue);
                                        }
                                        catch
                                        {
                                            FAI.Value = 9999;
                                        }
                                        FAI.Position = 0;
                                        mp4.MeasureData.Add(FAI);
                                    }
                                }
                                //数据入队
                                Common.Station4Queue_R.Enqueue(mp4);
                                Step4 = Step4 + 1;
                            }
                            break;

                        case 111: //等待激光处理结果并轴回到初始位
                            if (MotionControl.CheckMoveDone(Machine.pos_RlaserInitialPos_Rstation7))
                            {
                                Step4 = Step4 + 1;
                            }
                            break;
                        #endregion

                        case 112: //摆臂到取料位置   打开摆臂右吸气     关闭量测真空
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RlaserInitialPos_Rstation7.X4AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X4初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RccdInitialPos_Rstation6.Z11AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ14初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在正限位安全位置，请检查");
                                break;
                            }
                            pp = Machine.pos_RrockInitialPos_Rstation5.Clone();
                            pp.isShowY4Position = false;
                            pp.isShowZ12Position = true;
                            pp.AxisPriority = "1";
                            if (MotionControl.AxesMove(pp) == true)
                            {
                                //走Y
                                pp = Machine.pos_Rrock2FetchPos_Rstation5.Clone();
                                pp.isShowY4Position = true;
                                pp.isShowZ12Position = false;
                                pp.AxisPriority = "1";
                                if (MotionControl.AxesMove(pp) == true)
                                {
                                    //走Z
                                    pp = Machine.pos_Rrock2FetchPos_Rstation5.Clone();
                                    pp.isShowY4Position = false;
                                    pp.isShowZ12Position = true;
                                    pp.AxisPriority = "1";
                                    if (MotionControl.AxesMove(pp))
                                    {
                                        Machine.do_量测右搬运工位后吸嘴吸.ON();
                                        Thread.Sleep(500);

                                        Machine.do_量测右定位机构载盘吸嘴吸.OFF();
                                        Machine.do_量测右上CCD载盘吸嘴吸.OFF();
                                        Machine.do_量测右上激光载盘吸嘴吸.OFF();
                                        Machine.do_量测右CCD旋转工位吸嘴吸.OFF();
                                        Thread.Sleep(200);
                                        Step4 = Step4 + 1;
                                    }
                                }
                            }
                            break;

                        case 113: //摆臂Z轴提升到安全位置
                            pp = Machine.pos_RrockInitialPos_Rstation5.Clone();
                            pp.isShowY4Position = false;
                            pp.isShowZ12Position = true;
                            pp.AxisPriority = "1";
                            if (MotionControl.AxesMove(pp) == true)
                            {
                                Step4 = Step4 + 1;
                            }
                            break;

                        case 114: //摆臂到放料位置   关闭摆臂真空   打开量测真空吸
                            if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RlaserInitialPos_Rstation7.X4AxisNum, (int)APSDefine.MIO_MEL) == false)      ////激光X4初始位置在负限位位置
                            {
                                MessageBox.Show("激光X轴不在负限位安全位置，请检查");
                                break;
                            }
                            else if (Machine.AdlinkCard.GetMotionIoSatus((short)Machine.pos_RccdInitialPos_Rstation6.Z11AxisNum, (int)APSDefine.MIO_MEL) == false)  ////上CCDZ14初始位置在正限位位置
                            {
                                MessageBox.Show("上CCD不在正限位安全位置，请检查");
                                break;
                            }
                            //TODO X轴移动到放料位
                            pp = Machine.pos_Rrock2PutPos_Rstation5.Clone();
                            pp.isShowY4Position = true;
                            pp.isShowZ12Position = false;
                            pp.AxisPriority = "1";
                            if (MotionControl.AxesMove(pp) == true)
                            {
                                pp = Machine.pos_Rrock2PutPos_Rstation5.Clone();
                                pp.isShowY4Position = false;
                                pp.isShowZ12Position = true;
                                pp.AxisPriority = "1";
                                if (MotionControl.AxesMove(pp) == true)
                                {
                                    Machine.do_量测右CCD旋转工位吸嘴吸.ON();
                                    Thread.Sleep(500);

                                    Machine.do_量测右搬运工位前吸嘴吸.OFF();
                                    Machine.do_量测右搬运工位中吸嘴吸.OFF();
                                    Machine.do_量测右搬运工位后吸嘴吸.OFF();
                                    Thread.Sleep(200);
                                    Step4 = Step4 + 1;
                                }
                            }
                            break;

                        case 115: //摆臂到安全位置   
                            pp = Machine.pos_RrockSaftPos_Rstation5.Clone();
                            pp.isShowY4Position = false;
                            pp.isShowZ12Position = true;
                            pp.AxisPriority = "1";
                            if (MotionControl.AxesMove(pp) == true)
                            {
                                pp = Machine.pos_RrockSaftPos_Rstation5.Clone();
                                pp.isShowY4Position = true;
                                pp.isShowZ12Position = false;
                                pp.AxisPriority = "1";
                                if (MotionControl.AxesMove(pp))
                                {
                                    Step4 = Step4 + 1;
                                }
                            }
                            break;

                        #region 旋转工位拍照计算  下料机械手取料完成
                        case 116:
                            //TODO 旋转45°
                            if (MotionControl.AxesMove(Machine.pos_Rrotate1Pos_Rstation8) == true)
                            {
                                Step4 = Step4 + 1;
                            }
                            break;

                        case 117:  //第一次拍照
                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.右工位5侧背光].Chanel, Common.lightList[(int)LIGHT_ENUM.右工位5侧背光].Value);
                            Thread.Sleep(50);
                            //string cord = string.Empty;
                            try
                            {
                                Reng = new VisionPlatform.VisionManager.Engine("Station5_Capture");
                                Reng.SetInputString("Index", "1");
                                Reng.SetInputNumber("Type", Common.ProductType);
                                Reng.ActionFun();
                                cord = Reng.GetOutputString("CmdResult");
                                Reng = null;
                            }
                            catch
                            {
                                cord = "Station5,1";
                                Common.AppendUiLog.Log("工位5第一次拍照异常...", LogType.Error);
                            }

                            while (cord != "Station5,1")
                            {
                                Thread.Sleep(5);
                            }

                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.右工位5侧背光].Chanel, 0);
                            Step4 = Step4 + 1;
                            break;

                        case 118:  //调用计算的视觉算子
                            try
                            {
                                Reng_Cal_1 = new VisionPlatform.VisionManager.Engine("Station5");
                                Reng_Cal_1.SetInputString("Index", "1");
                                Reng_Cal_1.ActionFun();
                                cord = Reng_Cal_1.GetOutputString("StationResult");
                            }
                            catch
                            {
                                cord = "Finish,1";
                            }

                            while (cord != "Finish,1")
                            {
                                Thread.Sleep(5);
                            }
                            Step4 = Step4 + 1;
                            break;

                        case 119:
                            //TODO 旋转45°
                            if (MotionControl.AxesMove(Machine.pos_Rrotate2Pos_Rstation8) == true)
                            {
                                Step4 = Step4 + 1;
                            }
                            break;

                        case 120: //第二次拍照
                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.右工位5侧背光].Chanel, Common.lightList[(int)LIGHT_ENUM.右工位5侧背光].Value);
                            //第二次拍照指令
                            Thread.Sleep(50);
                            cord = string.Empty;
                            try
                            {
                                Reng = new VisionPlatform.VisionManager.Engine("Station5_Capture");
                                Reng.SetInputString("Index", "2");
                                Reng.SetInputNumber("Type", Common.ProductType);
                                Reng.ActionFun();
                                cord = Reng.GetOutputString("CmdResult");
                                Reng = null;
                            }
                            catch
                            {
                                cord = "Station5_2";
                                Common.AppendUiLog.Log("工位5第二次拍照异常...", LogType.Error);
                            }

                            while (cord != "Station5,2")
                            {
                                Thread.Sleep(5);
                            }

                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.右工位5侧背光].Chanel, 0);
                            Step4 = Step4 + 1;
                            break;

                        case 121:
                            try
                            {
                                Reng_Cal_2 = new VisionPlatform.VisionManager.Engine("Station5");
                                Reng_Cal_2.SetInputString("Index", "2");
                                Reng_Cal_2.ActionFun();
                                cord = Reng_Cal_2.GetOutputString("StationResult");
                            }
                            catch
                            {
                                cord = "Finish,2";
                            }

                            while (cord != "Finish,2")
                            {
                                Thread.Sleep(5);
                            }
                            Step4 = Step4 + 1;
                            break;

                        case 122:
                            //TODO 旋转45°
                            if (MotionControl.AxesMove(Machine.pos_Rrotate3Pos_Rstation8) == true)
                            {
                                Step4 = Step4 + 1;
                            }
                            break;

                        case 123:  //第三次拍照
                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.右工位5侧背光].Chanel, Common.lightList[(int)LIGHT_ENUM.右工位5侧背光].Value);
                            Thread.Sleep(50);
                            cord = string.Empty;
                            try
                            {
                                Reng = new VisionPlatform.VisionManager.Engine("Station5_Capture");
                                Reng.SetInputString("Index", "3");
                                Reng.SetInputNumber("Type", Common.ProductType);
                                Reng.ActionFun();
                                cord = Reng.GetOutputString("CmdResult");
                                Reng = null;
                            }
                            catch
                            {
                                cord = "Station5,3";
                            }

                            while (cord != "Station5,3")
                            {
                                Thread.Sleep(5);
                            }

                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.右工位5侧背光].Chanel, 0);
                            Step4 = Step4 + 1;
                            break;

                        case 124:
                            try
                            {
                                Reng_Cal_3 = new VisionPlatform.VisionManager.Engine("Station5");
                                Reng_Cal_3.SetInputString("Index", "3");
                                Reng_Cal_3.ActionFun();
                                cord = Reng_Cal_3.GetOutputString("StationResult");
                                Common.RoteImage3 = Reng_Cal_3.GetOutputImage("ImageOrg");
                            }
                            catch
                            {
                                cord = "Finish,3";
                            }

                            while (cord != "Finish,3")
                            {
                                Thread.Sleep(5);
                            }
                            Step4 = Step4 + 1;
                            break;

                        case 125:
                            //TODO 旋转45°
                            if (MotionControl.AxesMove(Machine.pos_Rrotate4Pos_Rstation8) == true)
                            {
                                Step4 = Step4 + 1;
                            }
                            break;

                        case 126:// 第4次拍照
                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.右工位5侧背光].Chanel, Common.lightList[(int)LIGHT_ENUM.右工位5侧背光].Value);
                            Thread.Sleep(50);
                            cord = string.Empty;
                            try
                            {
                                Reng = new VisionPlatform.VisionManager.Engine("Station5_Capture");
                                Reng.SetInputString("Index", "4");
                                Reng.SetInputNumber("Type", Common.ProductType);
                                Reng.ActionFun();
                                cord = Reng.GetOutputString("CmdResult");
                                Reng = null;
                            }
                            catch
                            {
                                cord = "Station5,4";
                            }

                            while (cord != "Station5,4")
                            {
                                Thread.Sleep(5);
                            }
                            Common.light4.WriteData(Common.lightList[(int)LIGHT_ENUM.右工位5侧背光].Chanel, 0);
                            Step4 = Step4 + 1;
                            break;

                        case 127:
                            try
                            {
                                Reng_Cal_4 = new VisionPlatform.VisionManager.Engine("Station5");
                                Reng_Cal_4.SetInputString("Index", "4");
                                Reng_Cal_4.ActionFun();
                                cord = Reng_Cal_4.GetOutputString("StationResult");
                            }
                            catch
                            {
                                cord = "Finish,4";
                            }

                            while (cord != "Finish,4")
                            {
                                Thread.Sleep(5);
                            }
                            Step4 = Step4 + 1;
                            break;

                        case 128:    //旋转轴转到初始位置
                            MotionControl.AxesMoveNoWait(Machine.pos_RrotateInitialPos_Rstation8);//异步运动到安全位
                            Step4 = Step4 + 1;
                            break;

                        case 129:
                            //发送允许计算指令
                            //string strLeftStation5 = string.Empty;

                            while (Reng_Cal_1.GetOutputString("StationResult") != "Finish,1" || Reng_Cal_2.GetOutputString("StationResult") != "Finish,2"
                                        || Reng_Cal_3.GetOutputString("StationResult") != "Finish,3" || Reng_Cal_4.GetOutputString("StationResult") != "Finish,4")
                            {
                                Thread.Sleep(10);
                            }

                            Reng_Cal_1 = null;
                            Reng_Cal_2 = null;
                            Reng_Cal_3 = null;
                            Reng_Cal_4 = null;
                            try
                            {
                                Reng = new VisionPlatform.VisionManager.Engine("DataCaculate FAI5-9");
                                Reng.ActionFun();
                                strLeftStation5 = Reng.GetOutputString("Station5Result");
                            }
                            catch
                            {
                                strLeftStation5 = strLeftStation5 = "LeftStation3OK" + "," + "FAI5:" + 9999 + "," + "FAI6:" + 9999 + "," + "FAI7:" + 9999 + "," + "FAI8:" + 9999 + "," + "FAI9:" + 9999;
                            }

                            //strLeftStation5 = strLeftStation5 = "RightStation3OK" + "," + "FAI5:" + 9999 + "," + "FAI6:" + 9999 + "," + "FAI7:" + 9999 + "," + "FAI8:" + 9999 + "," + "FAI9:" + 9999;
                            Common.AppendUiLog.Log(strLeftStation5, LogType.Alert);

                            //数据融合
                            string[] revData15_11 = strLeftStation5.Split(',');
                            MeasureProduct mp5_11 = new MeasureProduct();
                            Common.Station4Queue_R.TryDequeue(out mp5_11);
                            mp5_11.Position = "1";
                            for (int i = 0; i < revData15_11.Length; i++)
                            {
                                if (revData15_11[i].Contains(":"))
                                {
                                    string FAIName = revData15_11[i].Split(':')[0];
                                    string FAIValue = revData15_11[i].Split(':')[1];
                                    DataItem FAI = new DataItem();
                                    FAI.Name = FAIName;
                                    FAI.Value = double.Parse(FAIValue);
                                    FAI.Position = 0;
                                    mp5_11.MeasureData.Add(FAI);
                                }
                            }
                            //数据入队
                            Common.Station5Queue_R.Enqueue(mp5_11);
                            Step4 = Step4 + 1;
                            break;

                        case 130:      //整合产品的数据
                            MeasureProduct mp11 = new MeasureProduct();
                            Common.Station5Queue_R.TryDequeue(out mp11);
                            JUDGEMENT_RESULT ret1 = ProcessData.PrcessData(mp11);
                            Step4 = Step4 + 1;
                            break;

                        case 131:   //等待旋转轴转到初始位置
                            if (MotionControl.CheckMoveDone(Machine.pos_RrotateInitialPos_Rstation8))
                            {
                                Step4 = Step4 + 1;
                            }
                            break;

                        case 132:    //发送允许下料机械手取料的信号
                            if (Common.resultRight == true && Common.isResultRightRefresh == true)
                            {
                                Machine.do_给下工位右产品OK信号.ON();
                            }
                            else if (Common.resultRight == false && Common.isResultRightRefresh == true)
                            {
                                Machine.do_给下工位右产品NG信号.ON();
                            }
                            Step4 = Step4 + 1;
                            break;

                        case 133:     // //等待下料机械手到位,给破真空完成信号
                            if (Machine.di_下料机右机械手到位信号.GetStatus() == true)
                            {
                                Machine.do_量测右CCD旋转工位吸嘴吸.OFF();
                                Thread.Sleep(100);
                                Machine.do_给下料机右破真空完成.ON();
                                Step4 = Step4 + 1;
                            }
                            break;

                        case 134:     //等待下料机械手取料完成信号
                            if (Machine.di_下料右取料完成.GetStatus() == true || Common.DownRightRobotTakFinish == true)
                            {
                                Machine.do_给下料机右破真空完成.OFF();
                                Machine.do_给下工位右产品OK信号.OFF();
                                Machine.do_给下工位右产品NG信号.OFF();
                                Step4 = 56;
                            }
                            break;
                        #endregion
                        #endregion

                        /////理论上上料进盘不需要处理 只需要处理收try盘   下料需要处理搬运2、进try盘和收try盘    
                        #region 上料清料
                        case 56:     //触发右上料进盘清料 
                            Common.Clear右上料进盘 = true;
                            Step4 = Step4 + 1;
                            break;

                        case 57:  //等待上料进盘清料完成
                            if (Common.Clear右上料进盘完成 == true)
                            {
                                Common.Clear右上料收盘完成 = false;
                                Step4 = Step4 + 1;
                            }
                            break;

                        case 58:     //触发右上料收盘清料 
                            Common.Clear右上料收盘 = true;
                            Step4 = Step4 + 1;
                            break;

                        case 59:  //等待右上料收盘清料完成
                            if (Common.Clear右上料收盘完成 == true)
                            {
                                Common.Clear右上料收盘完成 = false;
                                Step4 = Step4 + 1;
                            }
                            break;
                        #endregion

                        #region NGtry清料
                        case 60:     // 
                            Common.Clear右NG盘 = true;
                            Step4 = Step4 + 1;
                            break;

                        case 61:  //
                            if (Common.Clear右NG盘完成 == true)
                            {
                                Common.Clear右NG盘完成 = false;
                                Step4 = Step4 + 1;
                            }
                            break;
                        #endregion

                        case 62:  //清料完成
                            MessageBox.Show("右穴清料完成");
                            Common.RightClearing = false;
                            RightClearFinish = true;
                            Right_MeasurementUpCCD.Instance.haveProduct = false;
                            Right_MeasurementLaser.Instance.haveProduct = false;
                            Step4 = 0;
                            break;
                    }
                }
            }
        }

        #region 中控智慧指纹锁相关函数
        /// <summary>
        /// 初始化指纹仪
        /// </summary>
        /// <returns>是否初始化成功，true成功，false失败</returns>
        public bool InitFPDevice()
        {
            try
            {
                if (!FPFuction.InitFPDevice())
                {
                    Common.AppendUiLog.Log("Fingerprint initial failed!", LogType.Error);
                    return false;
                }
                else
                {
                    Common.AppendUiLog.Log("Fingerprint initial ok!", LogType.Info);
                }

                if (!FPFuction.OpenFPDevice())
                {
                    Common.AppendUiLog.Log("Fingerprint open failed!", LogType.Error);
                    return false;
                }
                else
                {
                    Thread captureThread = new Thread(new ThreadStart(DoCapture));
                    captureThread.IsBackground = true;
                    captureThread.Start();

                    FPFuction.bIsTimeToDie = false;
                    Common.AppendUiLog.Log("Fingerprint open successful!", LogType.Info);
                }
            }
            catch (Exception er)
            {
                Common.AppendUiLog.Log("Fingerprint exception！", LogType.Error);
                return false;
            }
            return true;
        }

        /// <summary>
        /// 得到指纹图像后触发的事件函数
        /// </summary>
        private void DoCapture()
        {
            while (!FPFuction.bIsTimeToDie)
            {
                FPFuction.cbCapTmp = 2048;
                int ret = zkfp2.AcquireFingerprint(FPFuction.mDevHandle, FPFuction.FPBuffer, FPFuction.CapTmp, ref FPFuction.cbCapTmp);
                if (ret == zkfp.ZKFP_ERR_OK)
                {
                    try
                    {
                        FPFuction.SendMessage(this.Handle, FPFuction.MESSAGE_CAPTURED_OK, IntPtr.Zero, IntPtr.Zero);
                    }
                    catch (Exception ex)
                    {

                    }
                    finally
                    { }

                }
                Thread.Sleep(200);
            }
        }

        /// <summary>
        /// 重载窗口相应事件
        /// </summary>
        /// <param name="m"></param>
        protected override void DefWndProc(ref Message m)
        {
            switch (m.Msg)
            {
                case FPFuction.MESSAGE_CAPTURED_OK:
                    {
                        FPFuction.b_startScanFP = true;

                        MemoryStream ms = new MemoryStream();
                        BitmapFormat.GetBitmap(FPFuction.FPBuffer, FPFuction.mfpWidth, FPFuction.mfpHeight, ref ms);
                        Bitmap bmp = new Bitmap(ms);
                        this.pictureBox1.Image = bmp;

                        if (FPFuction.IsRegister)  //注册
                        {
                            int ret = zkfp.ZKFP_ERR_OK;
                            int fid = 0, score = 0;
                            ret = zkfp2.DBIdentify(FPFuction.mDBHandle, FPFuction.CapTmp, ref fid, ref score);

                            if (zkfp.ZKFP_ERR_OK == ret)
                            {
                                FPFuction.AppendUiLog("The fingerprint has been registered! fid = " + fid + "!", Color.Red);
                                FPFuction.IsRegister = false;
                                return;
                            }
                            if (FPFuction.RegisterCount > 0 && zkfp2.DBMatch(FPFuction.mDBHandle, FPFuction.CapTmp, FPFuction.RegTmps[FPFuction.RegisterCount - 1]) <= 0)
                            {
                                MessageBox.Show("Please press the same finger three times to register again！！ ", "Tips", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                FPFuction.AppendUiLog("Please press the same finger three times to register again", Color.Red);
                                FPFuction.IsRegister = false;
                                return;
                            }
                            Array.Copy(FPFuction.CapTmp, FPFuction.RegTmps[FPFuction.RegisterCount], FPFuction.cbCapTmp);
                            String strBase64 = zkfp2.BlobToBase64(FPFuction.CapTmp, FPFuction.cbCapTmp);
                            byte[] blob = zkfp2.Base64ToBlob(strBase64);
                            FPFuction.RegisterCount++;
                            if (FPFuction.RegisterCount >= FPFuction.REGISTER_FINGER_COUNT)
                            {
                                FPFuction.RegisterCount = 0;

                                if (zkfp.ZKFP_ERR_OK == (ret = zkfp2.DBMerge(FPFuction.mDBHandle, FPFuction.RegTmps[0], FPFuction.RegTmps[1], FPFuction.RegTmps[2], FPFuction.RegTmp, ref FPFuction.cbRegTmp)) &&
                                       zkfp.ZKFP_ERR_OK == (ret = zkfp2.DBAdd(FPFuction.mDBHandle, FPFuction.iFid, FPFuction.RegTmp)))
                                {
                                    FPFuction.iFid++;

                                    int i = 2047;
                                    for (; i >= 0; i--)
                                    {
                                        if (FPFuction.RegTmp[i] != 0)
                                            break;
                                    }
                                    int length = i + 1;
                                    String strRegTmp = zkfp2.BlobToBase64(FPFuction.RegTmp, length);
                                    FPFuction.FPInfo.UserFPFeatureData = strRegTmp;
                                    userFPInfoServices.InsertFPInfo2Table("UserFPInfo", FPFuction.FPInfo.UserName, FPFuction.FPInfo.UserAuthority, FPFuction.FPInfo.UserFPFeatureData);
                                    MessageBox.Show("Fingerprint entry completed!", "Tips", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                    FPFuction.AppendUiLog("Fingerprint registration successful!", Color.Green);
                                }
                                else
                                {
                                    MessageBox.Show("Fingerprint entry failed! error code = " + ret.ToString(), "Tips", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                    FPFuction.AppendUiLog("Fingerprint registration failed! error code = " + ret.ToString(), Color.Red);
                                }
                                FPFuction.IsRegister = false;
                                return;
                            }
                            else
                            {
                                FPFuction.AppendUiLog("You need to press " + (FPFuction.REGISTER_FINGER_COUNT - FPFuction.RegisterCount) + " times more", Color.Orange);
                            }
                        }
                        else
                        {
                            if (FPFuction.bIdentify)  //1:N识别 (暂时没用)
                            {
#if false
                                int ret = zkfp.ZKFP_ERR_OK;
                                int fid = 0, score = 0;
                                ret = zkfp2.DBIdentify(FPFuction.mDBHandle, FPFuction.CapTmp, ref fid, ref score);
                                if (zkfp.ZKFP_ERR_OK == ret)
                                {
                                    FPFuction.AppendUiLog("识别指纹成功，fid= " + fid + ", score = " + score + "!", Color.Green);
                                    return;
                                }
                                else
                                {
                                    FPFuction.AppendUiLog("识别指纹失败 , ret = " + ret.ToString(), Color.Red);
                                    return;
                                }
#endif
                            }
                            else  //1:1识别
                            {
                                //捞取数据库中的指纹信息
                                DataSet dataSet = userFPInfoServices.SelectTotalInfo("UserFPInfo");

                                if (dataSet.Tables[0].Rows.Count > 0)
                                {
                                    for (int i = 0; i < dataSet.Tables[0].Rows.Count; i++)
                                    {
                                        string FPFeatureData = dataSet.Tables[0].Rows[i]["UserFPFeatureData"].ToString();
                                        byte[] blob = new byte[2048];
                                        //blob = zkfp2.Base64ToBlob(FPFeatureData);
                                        if (FPFeatureData.Length < 16)
                                        {
                                            continue;
                                        }
                                        blob = Convert.FromBase64String(FPFeatureData);

                                        int r = zkfp2.DBMatch(FPFuction.mDBHandle, FPFuction.CapTmp, blob);
                                        if (r > 50)
                                        {
                                            FPFuction.FPInfo.UserName = dataSet.Tables[0].Rows[i]["UserName"].ToString();
                                            FPFuction.FPInfo.UserAuthority = dataSet.Tables[0].Rows[i]["UserAuthority"].ToString();

                                            Common.Authority = FPFuction.FPInfo.UserAuthority;

                                            ShowMessage(userNameTxt, FPFuction.FPInfo.UserName);
                                            ShowMessage(authorityTxt, FPFuction.FPInfo.UserAuthority);

                                            Common.fingerPrintAuthority = FPFuction.FPInfo.UserAuthority;
                                            Common.fingerPrintUserName = FPFuction.FPInfo.UserName;
                                            FPFuction.AppendUiLog("匹配成功! Score：" + r.ToString(), Color.Green);

                                            if (Common.Authority == "Apple" || Common.Authority == "CMT")// || Common.Authority == "CMT"
                                            {
                                                FPLoginSuccess = true;

                                                try
                                                {
                                                    ReleasePassCode();
                                                }
                                                catch (Exception)
                                                {
                                                }

                                                //添加登录记录
                                                try
                                                {
                                                    string FP_Owner = Common.fingerPrintUserName;
                                                    string FP_Authority = Common.fingerPrintAuthority;
                                                    DataSet dataSet_FP_Record = userFPInfoServices.SelectTotalInfo("FPLoginRecord");
                                                    Common.Id = dataSet_FP_Record.Tables[0].Rows.Count + 1;

                                                    string LoginStartTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                                                    userFPInfoServices.InsertFPRecord2Table("FPLoginRecord", Common.Id.ToString(), FP_Owner, FP_Authority, LoginStartTime);

                                                }
                                                catch (Exception ex)
                                                {

                                                }

                                                Common.isFileSetPassCode = false;
                                                string halconExamples = FileUtils.GetAppDirectory();

                                                HalconEngine HalconVisionOperate = new HalconEngine();
                                                Common.HalconvisionInitil = HalconVisionOperate.IntilCamerafile();

                                                Common.ProcedurePath = halconExamples + @"\hdevengine\procedures";

                                                if (Common.Authority == "Apple")
                                                {
                                                    Common.username = "superadmin";

                                                    SQLiteConnection conn = SQLiteUtils.GetConnection("test1");
                                                    SysUserServices sysUser = new SysUserServices();
                                                    sysUser.CreateUserTable("User", conn);
                                                    SysUserModel user = sysUser.GetModel(Common.username);

                                                    Common.password = user.Password;

                                                    Common.FPForm.ShowDialog(this);
                                                }

                                                if (FPLoginSuccess == true)
                                                {
                                                    FPLoginSuccess = false;
                                                    MessageBox.Show(this, "登陆成功!");
                                                }

                                            }
                                            break;
                                        }
                                        else
                                        {
                                            if (i == dataSet.Tables[0].Rows.Count - 1)  //最后一个也没有匹配到，证明没有录入指纹，非法权限
                                            {
                                                //再在Admin的数据库中匹配指纹
                                                DataSet dataSetAdmin = userFPInfoServices.SelectTotalInfo("AdminFPInfo");
                                                if (dataSetAdmin.Tables[0].Rows.Count > 0)
                                                {
                                                    for (int j = 0; j < dataSetAdmin.Tables[0].Rows.Count; j++)
                                                    {
                                                        FPFeatureData = dataSetAdmin.Tables[0].Rows[j]["UserFPFeatureData"].ToString();

                                                        r = zkfp2.DBMatch(FPFuction.mDBHandle, FPFuction.CapTmp, blob);


                                                        if (r > 50)
                                                        {
                                                            FPFuction.FPInfo.UserName = dataSetAdmin.Tables[0].Rows[j]["UserName"].ToString();
                                                            FPFuction.FPInfo.UserAuthority = "Admin";

                                                            Common.Authority = FPFuction.FPInfo.UserAuthority;
                                                            Common.fingerPrintAuthority = FPFuction.FPInfo.UserAuthority;
                                                            Common.fingerPrintUserName = FPFuction.FPInfo.UserName;

                                                            try
                                                            {
                                                                ReleasePassCode();
                                                            }
                                                            catch (Exception)
                                                            {
                                                            }

                                                            Common.isFileSetPassCode = false;
                                                            string halconExamples = FileUtils.GetAppDirectory();

                                                            HalconEngine HalconVisionOperate = new HalconEngine();
                                                            Common.HalconvisionInitil = HalconVisionOperate.IntilCamerafile();

                                                            Common.ProcedurePath = halconExamples + @"\hdevengine\procedures";

                                                            if (Common.Authority == "Admin")
                                                            {
                                                                Common.username = "superadmin";

                                                                SQLiteConnection conn = SQLiteUtils.GetConnection("test1");
                                                                SysUserServices sysUser = new SysUserServices();
                                                                sysUser.CreateUserTable("User", conn);
                                                                SysUserModel user = sysUser.GetModel(Common.username);

                                                                Common.password = user.Password;


                                                                Common.FPForm.ShowDialog(this);
                                                            }

                                                            break;
                                                        }
                                                        else
                                                        {
                                                            if (j == dataSetAdmin.Tables[0].Rows.Count - 1)  //最后一个也没有匹配到，证明没有录入指纹，非法权限
                                                            {
                                                                FPFuction.AppendUiLog("无任何权限指纹!!", Color.Red);
                                                                Common.Authority = "";

                                                                MessageBox.Show(this, "无任何权限指纹!", "识别结果", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                                                            }
                                                        }

                                                    }
                                                }
                                                else
                                                {
                                                    MessageBox.Show(this, "该用户不存在指纹信息!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                                }
                                            }
                                        }
                                    }

                                    FPFuction.bIdentify = true;
                                }
                                else
                                {
                                    //MessageBox.Show("读取部门数据失败!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                    FPFuction.AppendUiLog("Failed to read department data!", Color.Red);
                                }
                            }
                        }
                    }
                    break;

                default:
                    base.DefWndProc(ref m);
                    break;
            }
        }

        /// <summary>
        /// 指纹比对函数
        /// </summary>
        private void StartCompareFP()
        {
            //文本框清除
            ShowMessage(userNameTxt, "");
            ShowMessage(authorityTxt, "");

            if (FPFuction.bIdentify)  //要用1:1识别方法
            {
                FPFuction.bIdentify = false;
                FPFuction.AppendUiLog("Start identifying the fingerprint. Press in the fingerprint.......", Color.Green);
            }
        }
        #endregion

        #region 文件夹加密/解密相关函数
        public string pathkey
        {
            get { return _pathkey; }
            set { _pathkey = value; }
        }

        private string getstatus(string stat)
        {
            for (int i = 0; i < 6; i++)
                if (stat.LastIndexOf(arr[i]) != -1)
                    stat = stat.Substring(stat.LastIndexOf("."));
            return stat;
        }

        private bool checkpassword()
        {
            XmlTextReader read;
            if (pathkey == null)
                read = new XmlTextReader(RootFilepath + "\\Procedures.{2559a1f2-21d7-11d4-bdaf-00c04f60b9f0}" + "\\p.xml");
            else
                read = new XmlTextReader(RootFilepath + "\\Procedures.{2559a1f2-21d7-11d4-bdaf-00c04f60b9f0}" + "\\p.xml");
            if (read.ReadState == ReadState.Error)
                return true;
            else
            {
                try
                {
                    while (read.Read())
                        if (read.NodeType == XmlNodeType.Text)
                        {
                            if (read.Value == "1234")
                            {
                                read.Close();
                                return true;
                            }
                            else
                            {
                                read.Close();
                                return false;
                            }
                        }
                }
                catch { return true; }

            }
            read.Close();
            return false;
        }

        private Boolean setpassword(string path)
        {
            //frmPassword p = new frmPassword();

            XmlDocument xmldoc = new XmlDocument();
            XmlElement xmlelem;
            XmlNode xmlnode;
            XmlText xmltext;
            xmlnode = xmldoc.CreateNode(XmlNodeType.XmlDeclaration, "", "");
            xmldoc.AppendChild(xmlnode);
            xmlelem = xmldoc.CreateElement("", "ROOT", "");
            xmltext = xmldoc.CreateTextNode("1234");
            xmlelem.AppendChild(xmltext);
            xmldoc.AppendChild(xmlelem);
            xmldoc.Save(path + "\\p.xml");

            //p.path = path;
            //p.ShowDialog();
            return true;
        }

        public void SetPassCode()  //设置文件夹加密
        {
            try
            {
                //算法文件加密
                DirectoryInfo d = new DirectoryInfo(FilePath2);
                status = arr[0];
                setpassword(@"");
                if (!d.Root.Equals(d.Parent.FullName))
                {
                    d.MoveTo(d.Parent.FullName + "\\" + d.Name + status);//文件夹重命名
                }
                else d.MoveTo(d.Parent.FullName + d.Name + status);

            }
            catch (Exception ex)
            {
            }

        }

        public void ReleasePassCode() //设置文件夹解密
        {
            status = arr[0];

            DirectoryInfo d = new DirectoryInfo(FilePath);

            status = getstatus(status);
            bool s = checkpassword();
            if (s)
            {
                File.Delete(RootFilepath + "\\Procedures.{2559a1f2-21d7-11d4-bdaf-00c04f60b9f0}" + "\\key.xml");
                string path = FilePath.Substring(0, FilePath.LastIndexOf("."));
                d.MoveTo(path);
            }
        }
        #endregion

        private void Frm_Login_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Control && e.KeyCode == Keys.Escape)
            {

            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Left_MeasurementLocation.GrrPutProduct = true;
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            try
            {
                Common.LeftGrrCount = Convert.ToInt32(textBox1.Text);
            }
            catch
            {
                Common.LeftGrrCount = 1;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Right_MeasurementLocation.GrrPutProduct = true;
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {
            try
            {
                Common.RightGrrCount = Convert.ToInt32(textBox2.Text);
            }
            catch
            {
                Common.RightGrrCount = 1;
            }
        }

        private void labelX5_Click(object sender, EventArgs e)
        {

        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked)
            {
                Common.NouseDoor = true;
            }
            else
            {
                Common.NouseDoor = false;
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (Common.LeftClearing == true)
            {
                MessageBox.Show("english:LeftClearing!--chinese:左侧正在清料");
                return;
            }
            Thread thLeftClera = new Thread(LeftClera);
            thLeftClera.IsBackground = true;
            thLeftClera.Start();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            if (Common.RightClearing == true)
            {
                MessageBox.Show("english:RightClearing!--chinese:右侧正在清料");
                return;
            }
            Thread thLefttClera = new Thread(RightClera);
            thLefttClera.IsBackground = true;
            thLefttClera.Start();
        }
    }
}
